Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have very simple GridView as seen here called GridView1

Inside of it I have dropdown list called DropDownList1

<asp:TemplateField HeaderText="Counselors Selection">
<itemtemplate>
<asp:DropDownList ID="DropDownList1" Width="100%" runat="server" DataSourceID="SqlDataSource2" DataTextField="user_name" DataValueField="user_name" AutoPostBack="True" AppendDataBoundItems="true">
<asp:ListItem Text="--Select--" Value="">

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ocean4d_devConnectionString %>" SelectCommand="SELECT [user_name] FROM [AgencyUser] WHERE ([agency_id] = @agency_id)">
<SelectParameters>
<asp:SessionParameter Name="agency_id" SessionField="agency_id" Type="Int32" />
</SelectParameters>




How can I in asp.net VisualBasic read the value of it?

I know when it is a normal dropdownlist I would type something like

respose.write(dropdownlist1.selectedvalue)

Anyone can help?

Tnx
Posted

you can get it in row updating event like this..

C#
protected void YourGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
  DropDownList ddl= (DropDownList )YourGrid.Rows[e.RowIndex].FindControl("ddlId");
  string selectedvalue=ddl.selectedvalue;
 }
 
Share this answer
 
For Each row As GridViewRow In GridView1.Rows
Dim dropDownListText As String = CType(row.FindControl("DropDownList1"),DropDownList).SelectedItem.Value
Response.Write(dropDownListText)
Next

This seems to be working but now I am 50% done

Problem is that now I dont know since there can be multiple rows selected for which row does this dropdown reffer to.

Anyone has an idea how to get now the value of client id?
<asp:boundfield datafield="client_id" headertext="Client #" insertvisible="False" readonly="True" sortexpression="client_id" xmlns:asp="#unknown" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900