GridView的变化不是在绑定数据表显示 [英] GridView changes not showing in binded datatable

查看:123
本文介绍了GridView的变化不是在绑定数据表显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView的设置与我试图绑定到数据表..然后我通过网页进行一些修改GridView的价值观。然后我去点击一个按钮的code后面,看到DataTable中仍然有它的旧值...

I have a GridView setup with I've tried to bind to DataTable .. I then make some changes to the GridView's values through the webpage .. Then I go behind the code of a button click, and see that the DataTable still has the old values in it ...

ASPX标记code为GridView:

<asp:gridview ID="ESBAndTSRValuesInputGridView" runat="server" ShowFooter="true" AutoGenerateColumns="false">
        <Columns>
        <asp:BoundField DataField="Award ID" HeaderText="Award ID" Visible="false" />
        <asp:BoundField DataField="Award Name" HeaderText="Award Name" />
        <asp:TemplateField HeaderText="ESB Value">
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="TSR Value">
            <ItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
</asp:gridview>

从按钮点击code-背后GridView控件初始化数据:

DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Award ID", typeof(string)));
dt.Columns.Add(new DataColumn("Award Name", typeof(string)));
dt.Columns.Add(new DataColumn("ESB Value", typeof(string)));
dt.Columns.Add(new DataColumn("TSR Value", typeof(string)));
DataRow[] PSPAwards =  dtAwards.Select("AWARDTYPE = 'PSP'");
foreach (DataRow dr in PSPAwards)
{
    dt.Rows.Add(dr["AWARDID"].ToString(), dr["AWARDNAME"].ToString(), "0", "100");
}
ViewState["ESBAndTSRValuesDataTable"] = dt;
ESBAndTSRValuesInputGridView.DataSource = dt;
ESBAndTSRValuesInputGridView.DataBind();

在上面的code,你可以看到我使用默认值0和100初始化行。这是我从网页更改这些值后,调试事件过程中看到..

In the above code, you can see that I initialize the rows with default values 0 and 100 .. This is what I see during a debug event after making changes to these values from the webpage ..

我怎样才能使GridView控件自动持续做它的链接数据表的所有更改?

How can I make the GridView automatically persist all changes done to it to its linked DataTable ?

我使用.NET 2.0框架与VS2005 ..

I'm using .NET 2.0 Framework with VS2005 ..

推荐答案

试试这个

您的网格视图

 <asp:gridview ID="ESBAndTSRValuesInputGridView" runat="server" ShowFooter="true" AutoGenerateColumns="false">
        <Columns>
        <asp:BoundField DataField="AwardID" HeaderText="Award ID" Visible="false" />
        <asp:BoundField DataField="AwardName" HeaderText="Award Name" />
        <asp:TemplateField HeaderText="ESBValue">
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" Text='<%# Eval("ESBValue") %>' runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="TSR Value">
            <ItemTemplate>
                <asp:TextBox ID="TextBox2" Text='<%# Eval("TSRValue") %>'  runat="server"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
</asp:gridview>

在code后面

        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("AwardID", typeof(string)));
        dt.Columns.Add(new DataColumn("AwardName", typeof(string)));
        dt.Columns.Add(new DataColumn("ESBValue", typeof(string)));
        dt.Columns.Add(new DataColumn("TSRValue", typeof(string)));
        DataRow[] PSPAwards = dtAwards.Select("AWARDTYPE = 'PSP'");
        foreach (DataRow dr in PSPAwards)
        {
            dt.Rows.Add(dr["AWARDID"].ToString(), dr["AWARDNAME"].ToString(), "0", "100");
        }
        ViewState["ESBAndTSRValuesDataTable"] = dt;
        ESBAndTSRValuesInputGridView.DataSource = dt;
        ESBAndTSRValuesInputGridView.DataBind();

这篇关于GridView的变化不是在绑定数据表显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆