0
Posted on 4:58 AM by Softminer and filed under ,

  1.  <asp:BoundField DataField="ID" HeaderText="ID" >

  2.   </asp:BoundField>

  3. <asp:TemplateField HeaderText="ID" SortExpression="ID" >

  4.     <EditItemTemplate>

  5.         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>

  6.     </EditItemTemplate>

  7.     <ItemTemplate>

  8.         <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>

  9.     </ItemTemplate>

  10. </asp:TemplateField>

  11. <asp:TemplateField>

  12.     <ItemTemplate>

  13.         <asp:ImageButton ID="imgbutton" runat="server" CausesValidation="false" CommandName="Delete" ImageUrl="images.png" Text=""  CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ToolTip="delete file" />

  14.     </ItemTemplate>

  15. </asp:TemplateField>

  16. # in Code Behind

  17.  protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)

  18. {

  19.         if (e.CommandName == "Delete")

  20.         {

  21.             int rowIndex = Convert.ToInt32(e.CommandArgument);

  22.             GridViewRow row = (sender as GridView).Rows[rowIndex];

  23.             int Id = (int)Grid.DataKeys[row.RowIndex].Value;

  24.         }

  25. }

  26. protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)

  27.     {

  28.         if (e.Row.RowType == DataControlRowType.DataRow)

  29.         {

  30.             DataRowView rowView = (DataRowView)e.Row.DataItem;

  31.             ImageButton imgButton = (ImageButton)e.Row.Cells[1].Controls[1];

  32.         }

  33.     }

  34.              

0
Responses to ... TemplateField & BoundField & Command Field in Gridview C# ASP.NET