Listbox help

Discussion in 'ASP .Net Datagrid Control' started by Matt, May 9, 2006.

  1. Matt

    Matt Guest

    Hello Everyone,

    First let me thank you for taking the time to read this post. I am
    pretty new to asp.net and I have what could be a minor question about
    it. I am working with a datagrid and in one of the columns there is a
    multiple selection listbox. The code is pretty standard:

    <asp:datagrid id="dgUsers" runat="server"
    onupdatecommand="dgUsers_Update" oneditcommand="dgUsers_Edit"
    oncancelcommand="dgUsers_Cancel" ondeletecommand="dgUsers_Delete"
    cellpadding="2" autogeneratecolumns="false"
    edititemstyle-cssclass="ResultsSelectedItem"
    itemstyle-cssclass="ResultsItem" headerstyle-horizontalalign="center"
    headerstyle-cssclass="TableHeader" onitemcreated="DataGridItemCreated">

    <EditItemStyle CssClass="ResultsSelectedItem"></EditItemStyle>
    <ItemStyle CssClass="ResultsItem"></ItemStyle>
    <HeaderStyle HorizontalAlign="Center"
    CssClass="TableHeader"></HeaderStyle>
    <Columns>
    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
    HeaderText="Action" CancelText="Cancel"
    EditText="Edit"></asp:EditCommandColumn>
    <asp:templatecolumn headertext="Databases"
    headerstyle-horizontalalign="center"
    headerstyle-cssclass="TableHeader">
    <itemtemplate>
    <%# DataBinder.Eval(Container.DataItem, "UserDatabases") %>
    </itemtemplate>
    <edititemtemplate>
    <asp:ListBox ID="lbDatabases" Runat="server" SelectionMode=Multiple
    datavaluefield="DBID" datatextfield="DBName"
    DataSource="<%#ListBoxDataView%>">
    </asp:ListBox>
    </edititemtemplate>
    </asp:templatecolumn>
    <asp:ButtonColumn Text="Delete" ButtonType="PushButton"
    HeaderText="Action" CommandName="Delete"></asp:ButtonColumn>
    </Columns>
    </asp:datagrid>

    I removed the other fields from the datagrid because I don't feel that
    they are important to this issue. The vb code associated when clicking
    edit looks like this. I am just putting the part where I try to assign
    the listbox to a local variable, so I can use it.

    Dim lstbxDatabases As ListBox =
    CType(E.Item.Cells(8).FindControl("lbDatabases"), ListBox)
    Dim lstbxDatabases As ListBox = E.Item.FindControl("lbDatabases")
    Dim lstbxDatabases As ListBox = E.Item.Cells(8).Controls(0)

    I tried this each of the way above and for the first two, the value of
    listbxDatabases is nothing. For the last one, I get a casting error on
    the webpage. Note, I have it say that the cell is 8 because that is
    where it will be on the full datagrid.

    If you need any more information or if there is something noticable
    that I left out, please let me know.

    Thanks again for all of your time.

    Matt
    Matt, May 9, 2006
    #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. blenderdude
    Replies:
    0
    Views:
    749
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    389
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    861
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,307
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Chris Kettenbach

    Listbox selection to populate another listbox?

    Chris Kettenbach, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,633
    Chris Kettenbach
    Jun 16, 2005
Loading...

Share This Page