protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { if (GridView1.SelectedRow != null) { // Retrieve the data from the selected row int id = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text); string selectedData = GridView1.SelectedRow.Cells[1].Text; // Store the id in the hidden field SelectedIdHiddenField.Value = id.ToString(); // Display the selected data in the TextBox TextBox1.Text = selectedData; } }
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="custom-grid fixed-header" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoPostBack="true"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" /> <%--<asp:BoundField DataField="Sr_No" HeaderText="Sr_No" ItemStyle-Width="100px" ItemStyle- HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />--%> <asp:BoundField DataField="hobbies" HeaderText="Hobbies" ItemStyle-Width="1100px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" SortExpression="hobbies" /> </Columns> </asp:GridView>
true
ShowSelectButton
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)