网格视图更新,不起作用

时间:2014-05-08 23:41:39

标签: c# gridview

我有一个gridview gVEmployee。我想只更新一个 txtCheckIn 字段。

   <asp:GridView ID="gvEmployee" runat="server" AllowPaging="true" ShowFooter="true"
            PageSize="5" AutoGenerateColumns="false"
            HeaderStyle-BackColor="Red"
            HeaderStyle-ForeColor="White" BackColor="#FFCC66" OnRowEditing="GridView1_RowEditing" OnRowUpdating="gvEmployee_RowUpdating">
            <AlternatingRowStyle BackColor="#FFFFCC" />
            <Columns>

                <asp:BoundField DataField="WeekDays" HeaderText="WeekDays" SortExpression="WeekDays" ItemStyle-HorizontalAlign="center">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                </asp:BoundField>

                <asp:TemplateField HeaderText="Date" SortExpression="DateSelcted">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkcheckin" OnClick="lnkbtn_onclick" Text='<%#Eval("Dateselcted")%>' runat="server" CommandArgument='<%#Eval("Dateselcted")%>' />
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Name">

                    <ItemTemplate>

                        <asp:Label ID="lblCheckIn" runat="server" Text='<%#Eval("checkin") %>'></asp:Label>

                    </ItemTemplate>

                    <EditItemTemplate>

                        <asp:TextBox ID="txtCheckIn" runat="server" Text='<%#Eval("checkin") %>'></asp:TextBox>

                    </EditItemTemplate>


                </asp:TemplateField>

                <asp:TemplateField HeaderText="Edit">

                    <ItemTemplate>

                        <asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />

                        <br />

                        <span onclick="return confirm('Are you sure you want to delete this record?')">

                            <asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />

                        </span>

                    </ItemTemplate>

                    <EditItemTemplate>

                        <asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />

                        <br />

                        <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />

                    </EditItemTemplate>


                </asp:TemplateField>

            </Columns>
        </asp:GridView>

实施为:

protected void gvEmployee_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

    TextBox checkin = (TextBox)gvEmployee.Rows[e.RowIndex].FindControl("txtCheckIn");

    db.UpdateReg1(Convert.ToDateTime(eid), 2);
    gvEmployee.EditIndex = -1;
    BindGridView();
}

我的网格视图字段未更新。在调试时,我发现 checkin 的值保持不变。这里似乎有什么问题?

1 个答案:

答案 0 :(得分:0)

只需要在

中添加GridView
                protected void Page_Load(object sender, EventArgs e)
                {   
                if (!IsPostBack)
                    {
                    BindGridView();
                    }
                } 
相关问题