I have an asp.net repeater control, displaying data from a sql db.
I have delete, edit and save buttons displaying next to each record, sort of like an admin.
When edit is clicked, hidden textboxes appear in place of the literals that were displaying the data.
When save is clicked, the new values should be saved to the db (which they are), and the literals display the new value.
But the new value strings are returning as empty strings. They're not null, but the string contains no characters!
This worked fine when I had two TextBox's , however when I switched one to a HTMLTextArea , this happened!
Here is my relevant code...
if (e.CommandName == "edit")
{
((TextBox)e.Item.FindControl("Onebox")).Visible = true;
((TextBox)e.Item.FindControl("Onebox")).Text = ((Literal)e.Item.FindControl("onelit")).Text;
((HtmlTextArea)e.Item.FindControl("Threebox")).Visible = true;
((HtmlTextArea)e.Item.FindControl("Threebox")).Value = ((Literal)e.Item.FindControl("threelit")).Text;
DataTable dt = new DataTable();
DataTable dt2 = new DataTable();
((Literal)e.Item.FindControl("onelit")).Visible = false;
((Literal)e.Item.FindControl("threelit")).Visible = false;
((LinkButton)e.Item.FindControl("LinkButton2")).Visible = false;
((LinkButton)e.Item.FindControl("LinkButton3")).Visible = true;
}
if (e.CommandName == "save")
{
string newoneval = ((TextBox)e.Item.FindControl("Onebox")).Text;
string newtwoval = ((HtmlTextArea)e.Item.FindControl("Threebox")).Value;
((TextBox)e.Item.FindControl("Onebox")).Visible = false;
((Literal)e.Item.FindControl("onelit")).Text = ((TextBox)e.Item.FindControl("Onebox")).Text;
((HtmlTextArea)e.Item.FindControl("Threebox")).Visible = false;
((Literal)e.Item.FindControl("threelit")).Text = ((HtmlTextArea)e.Item.FindControl("Threebox")).Value;
((Literal)e.Item.FindControl("onelit")).Visible = true;
((Literal)e.Item.FindControl("threelit")).Visible = true;
((LinkButton)e.Item.FindControl("LinkButton2")).Visible = true;
((LinkButton)e.Item.FindControl("LinkButton3")).Visible = false;
if(newoneval != null && newtwoval != null)
{
SqlDataReader dataReader;
String editstr = "update news set title = '" + newoneval + "', short_desc ='" + newtwoval + "' where pk_ID = #pk_ID";
SqlCommand command = new SqlCommand(editstr, conn);
command.Parameters.AddWithValue("#pk_ID", e.CommandArgument);
try
{
conn.Open();
dataReader = command.ExecuteReader();
dataReader.Close();
command.Dispose();
conn.Close();
BindRepeater();
}
catch (Exception exc)
{
Response.Write(exc);
}
}
else
{
Response.Write("No value");
}
and here is the asp repeater template...
<asp:Repeater ID="list_holder" runat="server" OnItemCommand="runCommands">
<ItemTemplate>
<table>
<tr>
<!-- FIRST BOX CONTROLS ---------------->
<td class="cells">
<asp:Textbox id="Onebox"
text=''
runat="server"
enabled="true"
visible="false">
</asp:Textbox>
<asp:Literal id="onelit"
runat="server"
text='<%# DataBinder.Eval(Container.DataItem ,"title") %>'
/>
</td>
<td class="cells">
<textarea id="Threebox"
text=''
runat="server"
enabled="true"
Visible="false">
</textarea>
<asp:Literal id="threelit"
text='<%# DataBinder.Eval(Container.DataItem ,"short_desc") %>'
runat="server"
/>
</td>
<!-------------------------------------->
<!---- Link Buttons ------------------------>
<td class="cells">
<asp:LinkButton ID="LinkButton1"
runat="server"
CommandName="delete"
OnClientClick='javascript:return confirm("Are you sure you want to delete?")'
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false">Delete</asp:LinkButton>
</td>
<td class="cells">
<asp:LinkButton ID="LinkButton2"
runat="server"
CommandName="edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false"
Visible ="true">Edit</asp:LinkButton>
<asp:LinkButton ID="LinkButton3"
runat="server"
CommandName="save"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pk_ID") %>'
CausesValidation="false"
Visible ="false">Save</asp:LinkButton>
</td>
<!-------------------------------------------------->
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
Why are both the strings returning empty, when before they were returning correctly?
In ASP.NET when you set visible to false, Control don't render on page.
For more see MSDN.
Related
I made this popup that does not trigger the button I want it to. The user selects a contact, the contact is displayed with a delete button, when clicked, the confirmation popup appears with two more buttons, "Yes" and "No", they do not trigger for some reason.
ASPX:
<asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
<HeaderTemplate>
<table id="tblListContact">
<tr id="tblRowContact">
<th>
<asp:Label runat="server" Text="TRNSLTName" />
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:LinkButton runat="server" CommandName="selectContact" CommandArgument='<%# Eval("ID") %>'><%# Eval("Name") %></asp:LinkButton>
</td>
<asp:LinkButton CssClass="deleteContact" ID="btnDelete" CommandName="deleteContact" CommandArgument='<%# Eval("ID") %>' runat="server" OnClientClick="return OpenPopup(this)">
<asp:Image ImageUrl="Images/Icons/Deleted-16x16.png" ID="DeleteContact" runat="server" />
</asp:LinkButton>
<div id="myModal" class="modal">
<div class="modal-content">
<h3 class="modalHdr">
<asp:Label runat="server" Text="TRNSLTRemove users" /></h3>
<p>
<asp:Label runat="server" Text="TRNSLTDelete Contact"></asp:Label>
</p>
<asp:Button CommandName="noBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonNo" runat="server" Text="TRNSLTNo" CssClass="popupConfirm" />
<asp:Button CommandName="yesBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonYes" runat="server" Text="TRNSLTYes" CssClass="popupConfirm" />
</div>
</div>
</ItemTemplate>
C#:
/// <summary>
/// Assigning commands to repeater.
/// </summary>
protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
var contactId = Convert.ToInt64(e.CommandArgument);
switch (e.CommandName)
{
case "selectContact":
divRead.Visible = true;
ContactId = contactId;
var getContact = _ecSystem.GetContact(contactId);
if (getContact != null)
{
lblName.Text = getContact.Name;
lblPhone.Text = getContact.PhoneNumber;
lblMobile.Text = getContact.Cellphone;
lblAdress.Text = getContact.Street;
lblNotes.Text = getContact.Notes;
lblPage.Text = getContact.Homepage;
lblEmail.Text = getContact.Email;
imgPhone.Visible = !string.IsNullOrEmpty(lblPhone.Text);
imgMobile.Visible = !string.IsNullOrEmpty(lblMobile.Text);
imgAddress.Visible = !string.IsNullOrEmpty(lblAdress.Text);
imgNotes.Visible = !string.IsNullOrEmpty(lblNotes.Text);
imgPage.Visible = !string.IsNullOrEmpty(lblPage.Text);
imgEmail.Visible = !string.IsNullOrEmpty(lblEmail.Text);
}
break;
case "deleteContact": //It never comes to these statements
ContactId = contactId;
break;
case "noBtn": //It never comes to these statements
break;
case "yesBtn": //It never comes to these statements
if (ContactId != null)
{
_ecSystem.DeleteContact(ContactId.Value);
}
ContactId = null;
Response.Redirect("Contact.aspx");
break;
case "editContact":
divAdd.Visible = true;
_editMode = true;
var contacts = _ecSystem.GetContact(contactId);
if (contacts != null)
{
ViewState["Contacts"] = contacts;
}
break;
}
}
jQuery:
function OpenPopup($this) {
if ($($this).attr("disabled") === "disabled") {
return false;
}
var module = $($this).parent().find("#myModal");
module.show();
window.onclick = function (event) {
if (event.target === module) {
module.hide();
}
};
return false;
}
You always return false from OpenPopup. Since you use.
OnClientClick="return OpenPopup(this)"
The postback will be canceled if you return false from OnClientClick. Instead you should return true if you want to perform the server-click.
function OpenPopup($this) {
if ($($this).attr("disabled") === "disabled") {
return false;
}
var module = $($this).parent().find("#myModal");
module.show();
window.onclick = function (event) {
if (event.target === module) {
module.hide();
}
};
return true;
}
Apart from that you have a typo, following should be the same CommandName:
<asp:LinkButton ID="btnDelete" CommandName="deleteContact"
Code:
case "deleteBtn"
In your page you have
CommandName="deleteContact"
and in switch
case "deleteBtn"
they not match
in your switch you must use the same CommandName
case "deleteContact"
I have a repeater that I populate from a database:
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(#"SELECT CommunityName, CID, Budget FROM Donation WHERE Year = year(getdate()) ORDER BY CommunityName", conn);
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet myDataSet = new DataSet();
adp.Fill(myDataSet);
myRep.ItemDataBound += new RepeaterItemEventHandler(myRep_ItemDataBound);
myRep.DataSource = myDataSet;
myRep.DataBind();
}
void myRep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var textbox = e.Item.FindControl("community");
textbox.ClientIDMode = ClientIDMode.Static;
textbox.ID = "community" + (e.Item.ItemIndex + 1);
}
Repeater:
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Repeater ID="myRep" runat="server">
<ItemTemplate>
<div class="form-group">
<asp:Label ID='thisLbl' runat="server" Text='<%# Eval("CommunityName") %>' />
<asp:TextBox runat="server" ID="community" Text='<%# Eval("Budget") %>' CssClass="form-control" />
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
This creates 6 textboxes with labels and values, now my question is how do I detect which of these boxes belongs to the record it was initially pulled from in the database? I want to be able to modify the value in these boxes and hit a button to save them back to the database but I can't seem to wrap my head around getting them to the proper records.
Should I set the ID of the textbox to something I can parse through and match with the proper record? In the ItemDataBound?
You have to put a hidden field inside the repeater item template that takes the value from budget, and another hidden field to keep the CID value that has to be read in the post back request. Of course you need also a button and its click event handler.
<asp:Repeater ID="myRep" runat="server">
<ItemTemplate>
<div class="form-group">
<asp:Label ID='thisLbl' runat="server" Text='<%# Eval("CommunityName") %>' />
<asp:TextBox runat="server" ID="txtBudget" Text='<%# Eval("Budget") %>' CssClass="form-control" />
<asp:HiddenField runat="server" ID="hdOriginalBudget" Value='<%# Eval("Budget") %>' />
<asp:HiddenField runat="server" ID="hdCID" Value='<%# Eval("CID") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="btn" runat="server" OnClick="btn_Click" />
In your code behind you need to loop inside the repeater to check whether the text box has been changed by comparing its value to the hidden field. After you save the budget value in the database you need to realign the hidden field value to the the new value entered by the user, otherwise you will always save that value after each post back:
protected void btn_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in myRep.Items)
{
var txtBudget = item.FindControl("txtBudget") as TextBox;
var hdOriginalBudget = item.FindControl("hdOriginalBudget") as HiddenField;
var hdCID = item.FindControl("hdCID") as HiddenField;
if (txtBudget.Text != hdOriginalBudget.Value)
{
//If you enter here means the user changed the value of the text box
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(#"UPDATE Donation SET Budget = #Budget WHERE CID = #CID", conn);
cmd.Parameters.Add(new SqlParameter("#Budget", int.Parse(txtBudget.Text)));
cmd.Parameters.Add(new SqlParameter("#CID", int.Parse(hdCID.Value)));
conn.Open();
cmd.ExecuteNonQuery();
}
//After you write in the database realign the values
hdOriginalBudget.Value = txtBudget.Text;
}
}
}
Take care that my code is missing the most basic validation, so if the user writes an invalid value in the textbox (for example "yyy") it breaks. So please don't put it in production as it is!
I am trying to use the Telerik RadListView Drag-Drop feature:
http://demos.telerik.com/aspnet-ajax/listview/examples/datagrouping/defaultcs.aspx
The code below works fine but loops through all the items to find the "e.DestinationHtmlElement" which is not efficient. I want to be able to drag an item from one data group to another data group for Telerik RadListView with a better algorithm. How can I do that?
ASPX Code:
<telerik:RadListView runat="server" ID="Lsv_Vis" AllowPaging="True" PageSize="50"
ItemPlaceholderID="Phi_Vis_I" GroupPlaceholderID="Phi_Vis_G"
DataKeyNames="url_id, lst_id, url_name, url_address"
ClientDataKeyNames="url_id, lst_id, url_name, url_address"
OnItemDrop="CsVisItemDrop" OnItemDataBound="CsVisIDB" DataSourceID="Sql_Vis">
</telerik:RadListView>
<DataGroups>
<telerik:ListViewDataGroup GroupField="lst_id" DataGroupPlaceholderID="Phi_Vis_G">
<DataGroupTemplate>
<div class="Div_Vis_Grp"><span class="Spn_Vis"><%# (Container as RadListViewDataGroupItem).AggregatesValues["lst_name"].ToString() %></span></div>
<asp:Panel ID="Pnl_Vis" runat="server" CssClass="Pnl_Vis" ToolTip='<%# (Container as RadListViewDataGroupItem).DataGroupKey %>' onmouseover='this.className += " Vis_Sel";' onmouseout='this.className = this.className.split(" Vis_Sel").join("");'>
<asp:PlaceHolder ID="Phi_Vis_I" runat="server" />
</asp:Panel>
</DataGroupTemplate>
<GroupAggregates>
<telerik:ListViewDataGroupAggregate Aggregate="Max" DataField="lst_name" />
</GroupAggregates>
</telerik:ListViewDataGroup>
</DataGroups>
<ItemTemplate>
<div class="Div_Vis_Item rlvI">
<asp:Panel ID="Pnl_Vis" runat="server" ToolTip='<%# Eval("lst_id") %>' CssClass="Div_Vis_Item" onmouseover='this.className += " Vis_Sel";' onmouseout='this.className = this.className.split(" Vis_Sel").join("");'>
<a class="Hyp_Vis" runat="server" href='<%# Eval("url_address") %>' target="_blank">
<div class="Div_Vis_Body">
<div class="Div_Vis_Con">
<asp:Panel ID="Div_Vis_Con" runat="server" class="Div_Vis_Con" ToolTip='<%# Eval("lst_id") %>' ></asp:Panel>
</div>
</div>
<div class="Div_Vis_Link">
<asp:Label ID="Lbl_VisI" runat="server" Text='<%# Eval("url_name_short") %>' ToolTip='<%# Eval("url_name") %>'/>
</div>
</a>
</asp:Panel>
</div>
</ItemTemplate>
C# Code:
protected void CsVisItemDrop (object sender, RadListViewItemDragDropEventArgs e)
{
if (e.DestinationHtmlElement.IndexOf("Div_Vis_Con") < 0)
{
return;
}
foreach (RadListViewDataItem di in Lsv_Vis.Items)
{
Panel pnl = di.FindControl("Div_Vis_Con") as Panel;
if (pnl != null && pnl.ClientID == e.DestinationHtmlElement)
{
string uid = e.DraggedItem.GetDataKeyValue("url_id").ToString();
string lid = pnl.ToolTip.ToString();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Con_Str"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("UPDATE [MyTable] SET lst_id = #lst_id WHERE url_id = #url_id", conn))
{
cmd.Parameters.Add("#lst_id", SqlDbType.VarChar).Value = lid;
cmd.Parameters.Add("#url_id", SqlDbType.VarChar).Value = uid;
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch { }
}
}
}
}
Lsv_Vis.Rebind();
}
This question to related to a similar Data list question I posted some days ago. I have a datalist which displays Categories, and then documents within categories. What needs to happen is that documents under each category gets displayed in the order based on some numbers in file names. Documents are in format like '001-filename.pdf', '002-filename.pdf' ... '00x-filename.pdf'. I can use the first dash as some kind of 'split' function then grab the numbers like '001' etc to make the sorting to work. I think this could be done on either itemdatabound or in the sql syntax. I am posting the relevant code here. Any idea as to how I can make this to work? It is possible that there could be more than one document with shared number prefix: '001-filename.pdf', '001-filenameversion2.pdf' etc. Thanks!
ASPX:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical" DataKeyField="docid"
EnableViewState="True" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" id="tbl_data">
<tr runat="server" id="tr_category">
<td>
<asp:Label ID="lblHeader" runat="server" Font-Bold="True" Text='<%# Eval("categoryname") %>'
Font-Underline="True"></asp:Label>
<asp:Label runat="server" ID="lbl_cb_all">Select All
<asp:CheckBox runat="server" OnCheckedChanged="CheckAllChanged" AutoPostBack="true"
ID="cb_selectall" />
</asp:Label>
<asp:HiddenField ID="HiddenCatID" runat="server" Value='<%# Eval("CatID") %>' />
<asp:HiddenField ID="HiddenDocID" runat="server" Value='<%# Eval("docid") %>' />
</td>
</tr>
<tr runat="server" id="tr_data">
<td>
<asp:CheckBox runat="server" ID="cb_docid" Value='<%# Eval("docid") %>' OnCheckedChanged="displayselectedinit"
AutoPostBack="true" />
<asp:HyperLink ID="hpl_docfileencr" Text='<%# Eval("docfileencr") %>' NavigateUrl='<%# "~/PDFEncr/" + DataBinder.Eval(Container.DataItem, "docfileencr") %>'
Target="_blank" runat="server" />
<br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
C# CodeBehind:
sqlsyntax = #"SELECT dbo.projectsdocuments.docfileencr,dbo.categories.catid, dbo.categories.categoryname, dbo.projectsdocuments.docid
FROM dbo.Projects INNER JOIN dbo.projectsdocuments ON (dbo.Projects.projectid = dbo.projectsdocuments.projectid)
INNER JOIN dbo.categories ON (dbo.projectsdocuments.categoryid = dbo.categories.catid)
WHERE Projects.projectid = " + projectid + " ORDER BY dbo.categories.sortorder ASC";
protected void DataList1_ItemDataBound(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var row = (DataRowView)e.Item.DataItem;
var view = row.DataView;
var lastRow = e.Item.ItemIndex == 0 ? null : view[e.Item.ItemIndex - 1];
var tr_category = (System.Web.UI.HtmlControls.HtmlTableRow)e.Item.FindControl("tr_category");
var sameCategory = lastRow != null && (int)row["catid"] == (int)lastRow["catid"];
tr_category.Visible = !sameCategory;
}
}
Change your ORDER BY to include both columns.
SELECT
dbo.projectsdocuments.docfileencr,
dbo.categories.catid,
dbo.categories.categoryname,
dbo.projectsdocuments.docid
FROM dbo.Projects
INNER JOIN dbo.projectsdocuments
ON (dbo.Projects.projectid = dbo.projectsdocuments.projectid)
INNER JOIN dbo.categories
ON (dbo.projectsdocuments.categoryid = dbo.categories.catid)
WHERE Projects.projectid = " + projectid + "
ORDER BY dbo.categories.sortorder, dbo.projectsdocuments.docfileencr
The order by precedence is left to right, the default is "ASCENDING" but you can change a specific column sort by adding "ASC or DESC" directly after it.
** IMPORTANT NOTE **
Your code is susceptible to SQL Injection because your doing string concatenation. If this is a concern to you, change the SQL statement to use a named parameter that you assign using a command parameter (see example below).
Step 1: Change the inline string parameter, to a named parameter "#projectid".
SELECT
dbo.projectsdocuments.docfileencr,
dbo.categories.catid,
dbo.categories.categoryname,
dbo.projectsdocuments.docid
FROM dbo.Projects
INNER JOIN dbo.projectsdocuments
ON (dbo.Projects.projectid = dbo.projectsdocuments.projectid)
INNER JOIN dbo.categories
ON (dbo.projectsdocuments.categoryid = dbo.categories.catid)
WHERE Projects.projectid = #projectid
ORDER BY dbo.categories.sortorder, dbo.projectsdocuments.docfileencr
Step 2: Assign the parameter inline (example code)
using(SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
SqlCommand command = new SqlCommand(sql, conn);
command.CommandType = CommandType.Text;
// Assign the value projectid to the parameter #projectid
command.Parameters.Add(new SqlParameter("#projectid", projectid));
// Execute The Command (fill dataset, create datareader, etc...)
SqlDataReader reader = command.ExecuteReader();
}
I have 2 datalist and 2 btn UP and Down, I am trying to move the selected Image from one datalist to other datalist.
Datalist1:
<asp:DataList ID="dlstImage" runat="server" RepeatDirection="Horizontal" RepeatColumns="5"
CellSpacing="8" >
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
OnCommand="Select_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
<asp:Label ID="lbl" runat="server" Text="Figure"></asp:Label><%# dlstImage.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
Button:
<asp:ImageButton ID="ibtnMoveDown" runat="server" ImageUrl="~/App_Themes/Default/Images/movedown.bmp"
ToolTip="MoveDown The Item" OnClick="ibtnMoveDown_Click" />
<asp:ImageButton ID="ibtnMoveUp" runat="server" ImageUrl="~/App_Themes/Default/Images/moveup.bmp"
Style="height: 16px" ToolTip="MoveUp The Item" />
Datalist2:
<asp:DataList ID="dlstSelectedImages" runat="server" RepeatDirection="Horizontal"
RepeatColumns="5" CellSpacing="8">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
OnCommand="ImageSelect_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")+";"+Eval("Index")+";"+Eval("FileName") %>' /><br />
<asp:Label ID="nlbl" runat="server" Text="Figure"></asp:Label><%# dlstSelectedImages.Items.Count + 1%>
</ItemTemplate>
</asp:DataList>
Button Down code:
ArrayList ImgArry = new ArrayList();
path = objGetBaseCase.GetImages(TotImgIds);
ImgArry.Add(SelImgId);
ImgArry.Add(SelImgpath);//image name
ImgArry.Add(SelImgName);//image path
//path.Remove(ImgArry);
List<ArrayList> t = new List<ArrayList>();
if (newpath.Count > 0)
t = newpath;
t.Add(ImgArry);
newpath = t;
for (int i = 0; i < newpath.Count; i++)
{
ArrayList alst = newpath[i];
newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
dlstSelectedImages.DataSource = newtb;
DataBind();
path = objGetBaseCase.GetImages(TotImgIds);
for (int i = 0; i < path.Count; i++)
{
ArrayList alst = path[i];
tb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);
}
dlstImage.DataSource = tb;
DataBind();
I am selecting a image from datalist1 and transferring to datalist2, I am able to move the Image from one datalist to other datalist, But what I want is when I am moving the Image then Datalist1 Image which ever image I am moving that image get disable in Datalist1 after moving to datalist2, How to do that, how to disable the image in datalist1 after move to datalist2.
you probably jus need to call the DataBind() method at the proper time, which is after loading the two separate arrays like this
DataList1.DataBind();
DataList2.DataBind();
that should work fine if i am getting you correctly
protected void dlstImage_ItemDataBound(object sender, DataListItemEventArgs e)// for disabling the image after moving
{
ImageButton imgctrl = (e.Item.FindControl("Image") as ImageButton);
string[] str = imgctrl.CommandArgument.ToString().Split(';');
SelImgId = Convert.ToInt32(str[0]);
if (newpath.Exists(delegate(ArrayList imageDetails) { return Convert.ToInt32(imageDetails[0]) == SelImgId; }))
{
imgctrl.Enabled = false;
imgctrl.CssClass = "tdDisable";
}
else
{
imgctrl.Enabled = true;
imgctrl.CssClass = "";
}
}