Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually in my gridview in one column i taken itemtemplate and edittemplate as shown below

//aspx code
XML
<asp:TemplateField HeaderText="Staff" ControlStyle-ForeColor="#3366FF" SortExpression="Staff" >

            <EditItemTemplate>
            <asp:DropDownList ID="AssignedTo" runat="server" ></asp:DropDownList>

            </EditItemTemplate>

            <ItemTemplate >
            <asp:Label ID="lblstaff" runat="server" Text='<%#Eval("Staff") %>'></asp:Label>

            </ItemTemplate>
            </asp:TemplateField>


//now i want to bind data to dropdown list in .cs according to the label text.for that i want to find the label text while editing the row in rowcommand event like below is it possible

C#
protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {

                //here i want find the control of the label.text and by taking that value i will bind the data to dropdownlist 
            }
        }
Posted

1 solution

You can find Label control as below

C#
int index = Convert.ToInt32(e.CommandArgument);
      GridView customersGridView = (GridView)e.CommandSource;
      GridViewRow row = customersGridView.Rows[index];
Label lblstaff = row.FindControl("lblstaff") as Label;
var text = lblstaff.Text;
 
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