为什么获取不到模板列TextBox1的值?
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="ClassMaintain.WebForm3" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas. name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div><FONT face="宋体"></FONT><FONT face="宋体"></FONT><br>
<br>
</div>
<div>
<asp:datagrid id="dg1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
AutoGenerateColumns="False" DataKeyField="a" Font-Size="X-Small" BorderColor="#3366CC" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="4" Width="100%">
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
<ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="a" HeaderText="分类1"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="分类2">
<ItemTemplate>
<asp:Label id="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"b")%>'>Label</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TextBox1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"b")%>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="新增">
<ItemTemplate>
<asp:Button id="add" runat="server" Text="新增"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</div>
</form>
</body>
</HTML>
private void dg1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string t=((TextBox)e.Item.FindControl("TextBox1")).Text.Trim();
string str="update test set b='"+t+"' where a='"+dg1.DataKeys[e.Item.ItemIndex].ToString()+"'";
SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["con"]);
SqlCommand cmd=new SqlCommand(str,con);
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
dg1.EditItemIndex=-1;
Db();
Response.Write("<script>alert('"+t+"'+'"+dg1.DataKeys[e.Item.ItemIndex].ToString()+"');</script>");
}
为什么在编辑操作后,在TextBox1中输入值进行更新却没反应,无法抓到输入到TextBox1中的数值,请高手帮忙解决,谢谢!