By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

problem with button and listbox in edititemtemplate

P: n/a
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")).Item s.Clear();
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataS ource =
(user.GetFreeTU()).Tables[0];
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataV alueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataB ind();

((ListBox)e.Item.FindControl("lbxTU1Update")).Data Source =
(user.GetGroup(Int16.Parse(e.Item.Cells[0].Text))).Tables[0];
((ListBox)e.Item.FindControl("lbxTU1Update")).Data ValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTU1Update")).Data Bind();
}
}

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[i].Selected)
{
lbxTU1Update.Items.Add(lbxTUUpdate.Items[i].Text);
lbxTUUpdate.Items.Remove(lbxTUUpdate.Items[i].Text);
}
}
}
else
{
for (int i = 0; i < lbxTU1Update.Items.Count; i++)
{
if (lbxTU1Update.Items[i].Selected)
{
lbxTUUpdate.Items.Add(lbxTU1Update.Items[i].Text);
lbxTU1Update.Items.Remove(lbxTU1Update.Items[i].Text);
}
}
}
}
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
instead of button_click function, you can handle that in dg_ItemCommand
method.
chech if which button is clicked e.CommandName, and access the list boxes.

hth,
Av.
"yamne" <da***************@libero.it> wrote in message
news:e0**************@TK2MSFTNGP12.phx.gbl...
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")).Item s.Clear();
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataS ource =
(user.GetFreeTU()).Tables[0];
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataV alueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTUUpdate")).DataB ind();

((ListBox)e.Item.FindControl("lbxTU1Update")).Data Source =
(user.GetGroup(Int16.Parse(e.Item.Cells[0].Text))).Tables[0];
((ListBox)e.Item.FindControl("lbxTU1Update")).Data ValueField =
"UserName";
((ListBox)e.Item.FindControl("lbxTU1Update")).Data Bind();
}
}

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[i].Selected)
{
lbxTU1Update.Items.Add(lbxTUUpdate.Items[i].Text);
lbxTUUpdate.Items.Remove(lbxTUUpdate.Items[i].Text);
}
}
}
else
{
for (int i = 0; i < lbxTU1Update.Items.Count; i++)
{
if (lbxTU1Update.Items[i].Selected)
{
lbxTUUpdate.Items.Add(lbxTU1Update.Items[i].Text);
lbxTU1Update.Items.Remove(lbxTU1Update.Items[i].Text);
}
}
}
}

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.