Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using Command field. It will also auto-generate Update and Cancel buttons for you. Handle the events accordingly.</p> <p>Code below</p> <p><strong>ASPX</strong></p> <pre><code>&lt;asp:GridView ID="GridViewTopics" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" GridLines="Horizontal" OnRowEditing="GridViewTopics_RowEditing" CssClass="gridstyle" OnRowCancelingEdit="GridViewTopics_RowCancelingEdit" OnRowUpdating="GridViewTopics_RowUpdating" Style="margin-left: 30px;" Width="230px"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Topics"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="LabelTopicName" runat="server" Text='&lt;%# Eval("Name") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBoxEditTopicName" runat="server" Text='&lt;%# Bind("Name") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:CommandField ButtonType="Link" ShowEditButton="true"/&gt; &lt;/Columns&gt; &lt;HeaderStyle CssClass="headerclass" /&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>C#</strong></p> <pre><code>protected void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { GridViewTopics.DataSource = GetSomeSampleData(); GridViewTopics.DataBind(); } } private DataTable GetSomeSampleData() { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Id"); for (index = 1; index &lt;= 10; index++) { DataRow dr = dt.NewRow(); dr("Id") = index; dr("Name") = "SomeName" + index.ToString(); dt.Rows.Add(dr); } return dt; } protected void GridViewTopics_RowEditing(object sender, GridViewEditEventArgs e) { GridViewTopics.DataSource = GetSomeSampleData(); GridViewTopics.EditIndex = e.NewEditIndex; GridViewTopics.DataBind(); } protected void GridViewTopics_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { //Handle accordingly } protected void GridViewTopics_RowUpdating(object sender, GridViewUpdateEventArgs e) { //Handle accordingly } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload