Sometimes I want to be a value of the editing state. At this time, I usually don't use the template column to place the TEXTBOX by E.Item.FindControl. Some netizens ask why not get it? This depends on how your front desk is written, and the following is written in four situations and 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"
Buttype
= "Pushbutton"
CommandName
= "DEL"
>
ASP: ButtonColumn
>
Columns
>
ASP: DATAGRID
>
List 4 columns that everyone may encounter:
(1) Bind column
(2) A static string directly in the template column
(3) String binding directly in the template column
(4) String bonded by Label in the template column
Hereinafter, the way four values after the delete button is pressed:
IF
(e.commandname
==
"
Del
"
)
{Response.write (DataGrid1.columns [0] .Headertext ":" E.Item.cells [0] .Text "
"); response.write (DataGrid1.columns [1] .Headertext ":" E.Item.cells [1] .Text.trim () "
"); response.write (DataGrid1.columns [2] .Headertext ": (DatabaseLiteral Control) E.Item.cells [2] .Controls [0]). TEXT.TRIM () "
"); response.write (DataGrid1.columns [3] .Headertext ": ((label) E.Item.cells [3] .findControl ("Name")). Text "
");} (1) The first way to use the binding column can be taken directly through Cells [i] .text
(2) The second method can also be taken directly, but the annoying VS.NET always wraps the contents of the column in the front desk, so it also needs to remove the first end of the output.
(3) The third way is the most large number of netizens. You can't take the value directly through Cells [i] .Text, you can take the method given above, the same need to remove the first end
(4) The fourth way is the simplest way, of course, you can write E.Item.FindControl ("name") directly