problem with listbox and button in edititemtemplate datagrid

Discussion in 'ASP .Net Datagrid Control' started by yamne, Jun 17, 2004.

  1. yamne

    yamne Guest

    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);
    }
    }
    }
    }
    yamne, Jun 17, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yamne
    Replies:
    1
    Views:
    1,663
    avnrao
    Jun 17, 2004
  2. Replies:
    1
    Views:
    488
    Teemu Keiski
    Jun 22, 2005
  3. Dan
    Replies:
    0
    Views:
    908
  4. Problem with editing datagrid <EditItemTemplate>

    , Mar 24, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    135
  5. edititemtemplate datagrid problem

    , Sep 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    190
    Scott Mitchell [MVP]
    Sep 19, 2005
Loading...

Share This Page