C#,Asp.net,复选框没有在代码后面检查,虽然我点击了它

时间:2016-04-18 12:14:37

标签: c# html asp.net

所以我要做的是检查gridview中的复选框,并根据我想要更改数据库中的内容。 问题是,当我选中复选框时,它应该调用if语句(row.RowType == DataControlRowType.DataRow) 但它没有。这是文件背后的代码。 getAllLoans - 工作并呈现表格 isadmin - 也适用 - 如果用户是admin,则返回true / false

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Configuration; using System.Data; using System.Web.UI.WebControls; using GoldPay; using System.Web.UI;

        namespace GoldPay {
            public partial class WebForm2 : System.Web.UI.Page
            {
                protected void Page_Load(object sender, EventArgs e)
                {
                    if (Session["CurrentUser"] != null)
                    {
                        Money mon = (Money)Session["CurrentUser"];
                        Users user = mon.getUser();
                        string id = user.Id;
                        if (isAdmin(id) == true)
                        {
                            getAllLoans();

                        }
                    }
                }


                protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                {

                        e.Row.Cells[9].Visible = false;
                        if (e.Row.RowType == DataControlRowType.Header)
                        {
                            e.Row.Cells[1].Text = "ID";
                            e.Row.Cells[2].Text = "Reason For Loan";
                            e.Row.Cells[3].Text = "Amount Per Month";
                            e.Row.Cells[4].Text = "Currency";
                            e.Row.Cells[5].Text = "Total";
                            e.Row.Cells[6].Text = "Left To Pay";
                            e.Row.Cells[7].Text = "Num Pays";
                            e.Row.Cells[8].Text = "Left Num Pays";
                            e.Row.Cells[9].Text = "Approved";

                        }

                }



                protected void saveButton_Click(object sender, EventArgs e)
                {

                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            if (row.RowType == DataControlRowType.DataRow)
                            {
                                CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
                                if (chk != null && chk.Checked)
                                {
//unreached code, idk why
                                }

                            }
                        }
                    }
                }
            }

这是后面的代码,这是设计文件:

<table class="highlight">
<tr>   
<td>
    <asp:GridView ID="GridView1" runat="server" style="width: 958px; direction: ltr;"
        onrowdatabound="GridView1_RowDataBound">
        <Columns>
            <asp:TemplateField HeaderText="Approve">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="False" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</td>
</tr>
<tr><td>
    <asp:Button ID="saveButton" runat="server" class="waves-effect waves-light btn" 
        Text="Save" onclick="saveButton_Click" />
</td></tr>
</table>

0 个答案:

没有答案