Listbox help

M

Matt

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
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top