Datagrid
Sometimes you want to take a value that is not an edit state, this time usually does not use the template column to place the textbox through the E.item.findcontrol value, some users ask why not? It depends on how your front desk column is written, and here are four different scenarios and the following values in each of these four situations:
<asp:datagrid id= "DATAGRID1" runat= "Server" autogeneratecolumns= "False" allowpaging= "True" >
<Columns>
<asp:boundcolumn datafield= "VName" headertext= "name 0" ></asp:BoundColumn>
<asp:templatecolumn headertext= "Name 1" >
<ItemTemplate>
Name
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Name 2" >
<ItemTemplate>
<% #DataBinder. Eval (Container.DataItem, "VName")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Name 3" >
<ItemTemplate>
<asp:label id= "name" runat= "Server" text= ' <% #DataBinder. Eval (Container.DataItem, "VName")%> ' >
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:buttoncolumn text= "Delete" buttontype= "pushbutton" Commandname= "del" ></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
Lists 4 types of columns that you might encounter:
(1) Bound columns
(2) A static string is placed directly in the template column
(3) The string in the template column that binds directly
(4) A string that is bound by a label in the template column
The following is a description of the four values that are taken after the delete button is pressed:
if (e.commandname== "Del")
{
Response.Write (Datagrid1.columns[0]. headertext+ ":" +e.item.cells[0]. text+ "<br>");
Response.Write (Datagrid1.columns[1]. headertext+ ":" +e.item.cells[1]. Text.trim () + "<br>");
Response.Write (Datagrid1.columns[2]. headertext+ ":" + ((DataBoundLiteralControl) e.item.cells[2]. Controls[0]). Text.trim () + "<br>");
Response.Write (Datagrid1.columns[3]. headertext+ ":" + (Label) e.item.cells[3]. FindControl ("name")). text+ "<br>");
}
(1) The first type of binding column can be directly passed through Cells[i]. Text Fetch
(2) The second way can also be directly taken, but the annoying vs.net will always be in the foreground of the contents of the column line, so here also need to export things to remove the end of the space
(3) The third Way is to ask the most users, can not directly through the cells[i]. Text to the value, can be given by the above method to take, also need to remove the end of the space
(4) The fourth Way is also the simplest way, of course you can write directly E. Item.findcontrol ("name")