我有網格視圖,其中我想更新行,但它沒有發生。數據源是一個DataTable。請幫忙。GridView行不更新,從GridView中的文本框中的文本編輯模板不來
下面是標記
<asp:GridView ID="GrdV" runat="server" AutoGenerateColumns="false"
OnRowEditing="GrdV_RowEditing" OnRowUpdating="GrdV_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Clip Description">
<ItemTemplate>
<asp:Label ID="lblDescrptn" runat="server" Text='<%# Bind("Description") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="descTbx" runat="server" Text='<%# Bind("Description") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
,這背後是
protected void GrdV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// Retrieve the row being edited.
int index = GrdV.EditIndex;
GridViewRow row = GrdV.Rows[index];
TextBox t1 = row.FindControl("descTbx") as TextBox;
DataTable dt = (DataTable)Session["tmdataTable"];
dt.Rows[index]["Description"] = t1.Text; //Description is a column of my DataTable
dt.AcceptChanges();
GrdV.EditIndex = -1;
GrdV.DataSource = dt;
GrdV.DataBind();
}
在調試代碼,我發現文本框被傳遞空字符串t1.Text =""
即使我已經填寫文本框用新值。 我認爲錯誤是本着
TextBox t1 = row.FindControl("descTbx") as TextBox;
pageLoad的代碼
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GrdV.DataSource = Session["tmdataTable"];
GrdV.DataBind();
}
DataTable Finaldt = getTable();
GrdV.DataSource = Finaldt;
GrdV.DataBind();
Session["tmdataTable"] = Finaldt;
}
無效果需要e.RowIndex。仍然t1.text是空白 – 2013-04-06 07:34:21
看到我的更新。 – 2013-04-06 07:43:19
仍然沒有什麼,同樣的問題 – 2013-04-06 07:51:55