我正在使用 GridView 在 asp.net 应用程序中显示数据,并且数据在 cs 端代码中动态绑定。
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="grdView" runat="server" AutoGenerateColumns="false">
<Columns>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click"/></Triggers>
</asp:UpdatePanel>
没有问题,但是当我使用更新面板更新我的 GridView 时,它会将新数据附加到 GridView 中显示的旧数据中。 https://www.diigo.com/item/image/41snq/s18c
我的cs端代码是:
DataTable dt = _oBase.FillDataTable("Exec sp_Detail");
DataTable dtC = dt.DefaultView.ToTable(true, new[] { "TimeName" }); // Filter Row Name
DataTable dtH;
if (dt.Rows.Count > 0)
{
dtH = (from row in dt.AsEnumerable()
let tags = row.Field<string>("ColumnName")
orderby tags ascending
select row).CopyToDataTable();
dtH = dtH.DefaultView.ToTable(true, new[] { "ColumnName" }); // Filter Column Name
}
else
{
dtH = dt.DefaultView.ToTable(true, new[] { "ColumnName" });
}
var tFf = new TemplateField { HeaderTemplate = new MyGridViewTemplate(ListItemType.Header, "_", dtC, dt) };
//tFF.HeaderText = "";
tFf.HeaderStyle.CssClass = "mGrid";
tFf.ItemTemplate = new MyGridViewTemplate(ListItemType.Item, "", dtC, dt);
tFf.ItemStyle.Width = 50;
grdView.Columns.Add(tFf);
for (int i = 0; i < dtH.Rows.Count; i++)
{
var tF = new TemplateField { HeaderText = dtH.Rows[i][0].ToString() };
tF.HeaderStyle.CssClass = "mGrid";
tF.ItemTemplate = new MyGridViewTemplate(ListItemType.Item, dtH.Rows[i][0].ToString(), dtC, dt);
tF.ItemStyle.Width = 130;
grdView.Columns.Add(tF);
}
grdView.DataSource = dtC;
grdView.DataBind();