我有以下代码:
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack) {
bindList();
}
}
protected void dlAgents_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
dlAgents.EditItemIndex = e.Item.ItemIndex;
bindList();
}
protected void dlAgents_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item) {
((Label)e.Item.FindControl("lblName")).Text = e.Item.DataItem("AgentName");
((Label)e.Item.FindControl("lblAddress")).Text = e.Item.DataItem("Address");
((Label)e.Item.FindControl("lblContactNo")).Text = e.Item.DataItem("ContactNo");
((LinkButton)e.Item.FindControl("lnkLoginID")).Text = e.Item.DataItem("LoginEmailID");
}
}
protected void dlAgents_UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
GC.ExecuteCommand("update AgentMaster set Address='" + ((TextBox)e.Item.FindControl("txtAddress")).Text + "' , ContactNo='" + ((TextBox)e.Item.FindControl("txtContact")).Text + "' where agentid='" + e.CommandArgument + "'");
dlAgents.EditItemIndex = -1;
bindList();
}
在此代码中,对于 updatecommand,它始终为文本框取空白值 .. 例如。(TextBox)e.Item.FindControl("txtAddress")).Text
这个文本框是空白的,这就是为什么不能用正确的值更新。
请帮我。