Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I need to find selected text of dynamically created dropdown in gridview.Please help.
Posted
Comments
sharmarun 18-May-12 6:16am    
Can you Elaborate your question.
i am confusing that dropdown created inside the Grid or outside the Grid?
Member 619060 18-May-12 7:47am    
The dropdown is inside grid view

First you have to create a dropdown list dynamically and add it to gridview edit tempalte field in gridview row created event

then on row command event find that dropdownlis control like
VB
If e.CommandName = "Edit" Then
          Dim i As Integer = e.CommandArgument
          Dim row As GridViewRow = GridView2.Rows(i)

                  Dim dd As DropDownList       
   dd= DirectCast(row.FindControl("ddl1"), DropDownList)
           

      End If


it may help you
 
Share this answer
 
try this ,first take a template field then add item template,then inside edit template put the dropdown as follow...


XML
<asp:templatefield headertext="Status" sortexpression="with_status" xmlns:asp="#unknown">
                    <itemtemplate>
                        <asp:label id="Label1" runat="server" text="<%# Bind("with_status") %>"></asp:label>
                    </itemtemplate>

                    <edititemtemplate>
                        <asp:dropdownlist id="DropDownList1" runat="server">
                        <asp:listitem value="0">-Select- </asp:listitem>
                        <asp:listitem value="1">pending </asp:listitem>
                      <asp:listitem value="2">completed </asp:listitem>

                        </asp:dropdownlist>
                    </edititemtemplate>
                </asp:templatefield>



aspx.cs

on rowupdating put the following code
C#
DropDownList ddl2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
            if (ddl2.SelectedValue.ToString() != "0")
            {
                SqlDataSource1.UpdateParameters["with_status"].DefaultValue = ddl2.SelectedItem.ToString();
 
            }
 
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