0

这是我的网格视图:

   <asp:GridView ID="gvconsumer" runat="server" AutoGenerateColumns="False" Width="50%" >
        <Columns>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <asp:Label ID="lblid" runat="server" Text='<%# Bind("id") %>' Visible="false" ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Consumer">
                <ItemTemplate>
                    <asp:Label ID="lblconsumer" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblname" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Status">
                <ItemTemplate>
                    <asp:Label ID="lblstatus" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DateCreated">
                <ItemTemplate>
                    <asp:Label ID="lbldatecreaterd" runat="server" Text='<%# Bind("DateCreated") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <asp:Button ID="btnApprove" runat="server" Text="Approve" OnClick="btnApprove_Click" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <asp:Button ID="btnReject" runat="server" Text="Reject" OnClick="btnApprove_Click" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

这是我背后的代码:(AcceptButton)

 if (btnApprove_Click)
    GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow;

    string id = ((Label)row.FindControl("lblid")).Text;
    Response.Write(row.RowIndex);
    string ApprovedStatus = "Approved";

    string status = ClassBiller.ConsumerStatus(int.Parse(id), ApprovedStatus, DateTime.Now);

这是我的 ConsumerStatus() 数据层:

        string retUpdateStatus = "";

        string consumerStatus = "UPDATE MerchantConsumer SET Status = @Status, DateAccepted = @DateAccepted WHERE ConsumerID = @Consumerid";

        string[] param = { "@Consumerid", "@Status", "@DateAccepted" };
        object[] paramVal = { ConsumerID, Status, DateAccepted };

        try
        {
            ClassDBQuery.ExecNonQuery(consumerStatus, param, paramVal);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return retUpdateStatus;

这就是绑定 GridView 的方式:

    DataTable gridViewConsumer = new DataTable();
    gridViewConsumer = ClassConsumer.GetRows();

    gvconsumer.DataSource = gridViewConsumer;
    gvconsumer.DataBind();

我的问题是,我必须双击按钮来更新gridView的状态字段..但是当我检查数据库时(第一次点击),状态字段已经更新了..请帮助....

4

1 回答 1

2

db 操作成功后需要再次绑定网格。

于 2013-06-04T13:52:15.147 回答