0

我在页面加载时使用相同的数据源在同一字段上有一个asp:grid和一个。加载页面后,任何回发事件表都会刷新并显示空白表,但网格视图仍显示所有记录。asp:tableaspx page

谁能告诉我如何防止刷新asp:table任何回发事件?

编辑-1

代码GridTable填写

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        DataSet ds = new DataSet();
        ds = clsTransaction.Select(@"SELECT TOP 10000 A.reid AS [ID],
A.nm AS [Name],
B.nm AS [Server],
CASE WHEN D.nm IS NULL THEN A.nm ELSE D.nm END as [Parent],
CASE WHEN C.nm IS NULL THEN A.nm ELSE C.nm END as [Top Perent],
CASE WHEN A.isparent = 1 THEN 'Not a group reseller' ELSE 'Group reseller' END AS [Is Group] 
FROM tblReseller AS A
LEFT OUTER JOIN tblwser B on (A.wsid = B.wsid)
LEFT OUTER JOIN tblReseller AS C ON (A.tparentid = C.acid AND A.wsid = C.wsid)
LEFT OUTER JOIN tblReseller AS D ON (A.parentid = D.acid AND A.wsid = D.wsid)", DataSendBSSWEB.ServerDbEnum.MainSqlServer, false);

        #region Table fill
        TableRow tr = new TableRow();
        TableCell tc = new TableCell();
        foreach (DataColumn dc in ds.Tables[0].Columns)
        {
            tc = new TableCell();
            tc.Text = dc.ColumnName;
            tr.Cells.Add(tc);
        }
        tblview.Rows.Add(tr);
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            tr = new TableRow();
            foreach (object obj in dr.ItemArray)
            {
                tc = new TableCell();
                tc.Text = obj.ToString();
                tr.Cells.Add(tc);
            }
            tblview.Rows.Add(tr);
        }
        #endregion

        #region Grid Fill
        grvView.DataSource = ds.Tables[0];
        grvView.DataBind();
        grvView.EnableViewState = true;
        #endregion
    }
}
4

1 回答 1

1

asp:table 对象不是数据绑定控件,也不将其内容存储在 ViewState 中。我认为您应该将表的数据绑定到 if (!Page.IsPostBack):)之外

protected void Page_Load(object sender, EventArgs e)
{
    DataSet ds = new DataSet();
    ds = clsTransaction.Select(@"SELECT TOP 10000 A.reid AS [ID],
A.nm AS [Name],
B.nm AS [Server],
CASE WHEN D.nm IS NULL THEN A.nm ELSE D.nm END as [Parent],
CASE WHEN C.nm IS NULL THEN A.nm ELSE C.nm END as [Top Perent],
CASE WHEN A.isparent = 1 THEN 'Not a group reseller' ELSE 'Group reseller' END AS [Is     Group] 
FROM tblReseller AS A
LEFT OUTER JOIN tblwser B on (A.wsid = B.wsid)
LEFT OUTER JOIN tblReseller AS C ON (A.tparentid = C.acid AND A.wsid = C.wsid)
LEFT OUTER JOIN tblReseller AS D ON (A.parentid = D.acid AND A.wsid = D.wsid)",     DataSendBSSWEB.ServerDbEnum.MainSqlServer, false);

    #region Table fill
    TableRow tr = new TableRow();
    TableCell tc = new TableCell();
    foreach (DataColumn dc in ds.Tables[0].Columns)
    {
        tc = new TableCell();
        tc.Text = dc.ColumnName;
        tr.Cells.Add(tc);
    }
    tblview.Rows.Add(tr);
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        tr = new TableRow();
        foreach (object obj in dr.ItemArray)
        {
            tc = new TableCell();
            tc.Text = obj.ToString();
            tr.Cells.Add(tc);
        }
        tblview.Rows.Add(tr);
    }
    #endregion


if (!Page.IsPostBack)
{

    #region Grid Fill
    grvView.DataSource = ds.Tables[0];
    grvView.DataBind();
    grvView.EnableViewState = true;
    #endregion
}
}

如果您不想在每个 pageLoad 上填充表格,我建议asp:FormView您可以在此处
查看参考。 您可以在 FormView 的.
<ItemTemplate>

于 2013-07-20T06:37:33.693 回答