Avatar of national_fulfillment
national_fulfillment
Flag for United States of America asked on

C# getting values from a listbox inside a gridview

i have a listbox in a grid and i'm trying to access the values populated in the listbox during the row updating event.  
<ItemTemplate>
 <asp:ListBox ID="InsuranceLB" runat="server" Width="225px" Height="75px" SelectionMode="Multiple" style="margin-top:2px;" autoscroll="true"  /><br />
</ItemTemplate>
     <ItemStyle VerticalAlign="Top" />
 </asp:TemplateField>

This is how i'm trying to get the values
   ListBox myListBox = (ListBox)GridView1.Rows[e.RowIndex].Cells[14].FindControl("InsuranceLB");
       
An error isn't thrown but i don't get the listbox values either. Any direction would be appreciated. Thanks in advance.
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Gerry Bartley

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gerry Bartley

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
national_fulfillment

ASKER
Thanks i figured it out, the problem was that the listbox really was empty lol. I wasn't populating it again in the edit event. Thanks for the response, both ways (with or without the cell reference) works to get the items in the listbox from a grid.
Gerry Bartley

Since you figured it your yourself, no need to award points. Just click request Attention to close the question and get your points back
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes