You must Sign In to post a response.
  • Category: ASP.NET

    Display gridview selected row to dropdownlist using c#

    want to display gridview selected row value to dropdownlist.

    for that my code as follows
    protected void gvFacdet_SelectedIndexChanged(object sender, EventArgs e)
    txt_name.Text = gvFacdet.SelectedRow.Cells[1].Text.ToString();


    In gridview row as follows
    Name Designation
    select Ramesh Courseofficer

    in run mode as follows
    Name textbox
    Designation dropdownlist

    When i select the gridview row value that gridview selected row value to be displayed in respective textbox and dropdownlist

    In textbox name to be displayed and dropdownlist designation to be displayed.

    please help me what is the problem in my above code.
  • #761489
    Hello Rao,

    Refer the below code :

    HTML Markup :

    <asp:GridView ID="gv" runat="server">
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick = "LinkButton1_Click">Select</asp:LinkButton>

    Code behind :

    protected void LinkButton1_Click(object sender, EventArgs e)
    if (ddldesign.Items.Count > 0)
    txtName.Text = string.Empty;
    for (int i = 0; i < ddldesign.Items.Count; i++)

    GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
    int index = gvRow.RowIndex;

    txtName.Text = gv.Rows[index].Cells[0].Text;

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761492
    You can try this code

    <asp:GridView ID="Grd1" runat="server" OnSelectedIndexChanged="Grd1_SelectedIndexChanged" AutoGenerateSelectButton="True">
    <asp:BoundField DataField="Id" HeaderText="" />
    <asp:BoundField DataField="EmpNo" HeaderText="" />
    <asp:BoundField DataField="EmpName" HeaderText="" />
    <asp:BoundField DataField="Amount" HeaderText="" />


    <asp:DropDownList ID="drp1" runat="server" AutoPostBack="true">
    <asp:ListItem Text="aa1" Value="11"></asp:ListItem>
    <asp:ListItem Text="aa2" Value="12"></asp:ListItem>
    <asp:ListItem Text="aa3" Value="13"></asp:ListItem>


    protected void Grd1_SelectedIndexChanged(object sender, EventArgs e)
    GridViewRow grd1 = Grd1.SelectedRow;
    string ss = Grd1.SelectedRow.Cells[1].Text;

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments