使用Datatable进行GridView绑定 [英] GridView Binding using Datatable
问题描述
嗨朋友们,
我绑定了一个Gridview使用存储在会话中的数据表...现在我使用Tempalte Field在网格视图中添加了一个按钮(用于删除)...现在我想要要删除当前Row和aftervdeletion上的操作我想再次绑定gridview ...
重要说明这里使用Templare字段作为按钮...
http://www.dotnetfunda.com/articles/article29.aspx [ ^ ]
在这里您将获得所需信息。
您可以尝试这种方式
< pre lang =xml> < asp:TemplateField >
< I temTemplate >
< asp:按钮 ID = btnDelete runat = server 文本 = 删除 CommandName = 删除 / >
< / ItemTemplate >
< / asp:TemplateField < span class =code-keyword>>
protected void grvTest_RowCommand(对象发送者,GridViewCommandEventArgs e)
{
if(e.CommandName ==Delete)
{
GridViewRow row =(GridViewRow)((Button)e.CommandSource).NamingContainer;
DataTable dt =(DataTable)Session [CurrentTable];
dt.Rows.Remove(dt.Rows [row.RowIndex]);
grvTest.DataSource = dt;
grvTest.DataBind();
}
}
Hi Friends,
I have bind one Gridview Using datatable that is stored in session...Now i added one button(for delete) in grid view using Tempalte Field...now i want to do delete Operation on current Row and aftervdeletion I want to bind gridview again...
Important Note Here am using Templare field for button...
http://www.dotnetfunda.com/articles/article29.aspx[^]
here you will get required info.
you can try this way
<asp:TemplateField> <ItemTemplate> <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete"/> </ItemTemplate> </asp:TemplateField>
protected void grvTest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
DataTable dt = (DataTable)Session["CurrentTable"];
dt.Rows.Remove(dt.Rows[row.RowIndex]);
grvTest.DataSource = dt;
grvTest.DataBind();
}
}
这篇关于使用Datatable进行GridView绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!