problem with listbox and button in edititemtemplate datagrid

Y

yamne

I have a problem.
When I click in edit datagrid button I show two listbox and two button.
I use two button to move data between two listbox.

My problem is that I can't call the listbox in the button_click function
because the only way to find the listbox is:

(listbox)e.item.findcontrol["listboxId"]

What s the solution to this problem?
thanks
Damiano

My code is:

protected void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
((ListBox)e.Item.FindControl("lbxTUUpdate")).Items.Clear();
((ListBox)e.Item.FindControl("lbxTU1Update")).Items.Clear();
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataSource =
(user.GetFreeTU()).Tables[0];
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataBind();

((ListBox)e.Item.FindControl("lbxTU1Update")).DataSource =
(user.GetGroup(Int16.Parse(e.Item.Cells[0].Text))).Tables[0];
((ListBox)e.Item.FindControl("lbxTU1Update")).DataValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTU1Update")).DataBind();
}
}

and this in edititemtemplate:

<table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr align=center>
<td>
<asp:ListBox id="lbxTUUpdate" runat="server" Width="150px"
Height="150px" />
</td>
<td>
<asp:button Text=">>" commandname="Add" Runat="Server"
ID="btnAddUpdate" BorderWidth="1" BackColor="#ffffff" BorderColor="#000000"
/><br>
<asp:button Text="<<" commandname="Remove" Runat="Server"
ID="btnRemoveUpdate" BorderWidth="1" BackColor="#ffffff"
BorderColor="#000000" />
</td>
<td>
<asp:ListBox id="lbxTU1Update" runat="server" Width="150px"
Height="150px" />
</td>
</tr>
</table>

this is the button function (but don't work)

protected void lbxDisp(Object sender, CommandEventArgs e)
{
if (e.CommandName == "Add")
{
for (int i = 0; i < lbxTUUpdate.Items.Count; i++)
{
if (lbxTUUpdate.Items.Selected)
{
lbxTU1Update.Items.Add(lbxTUUpdate.Items.Text);
lbxTUUpdate.Items.Remove(lbxTUUpdate.Items.Text);
}
}
}
else
{
for (int i = 0; i < lbxTU1Update.Items.Count; i++)
{
if (lbxTU1Update.Items.Selected)
{
lbxTUUpdate.Items.Add(lbxTU1Update.Items.Text);
lbxTU1Update.Items.Remove(lbxTU1Update.Items.Text);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top