简体   繁体   English

单击按钮即可在gridview内进行复选框验证

[英]checkbox validation inside gridview on button click

I have checkbox column inside grid view and one button and one wizard control on page.. I need to validataion against checkbox in button click event like this .... If any of the check box is not checked i need to prevent to load the wizard step 2 .... But i am failed to do this 我在网格视图内有复选框列,在页面上有一个按钮和一个向导控件。.我需要针对按钮单击事件中的复选框进行验证,如....如果未选中任何复选框,则需要防止加载向导步骤2...。但是我做不到

I am adding all checked rows to another gridview that I was setup in wizardStep : 1 我将所有选中的行添加到在向导中设置的另一个gridview中:1

and this is my code ... 这是我的代码...

protected void Update_Onclick(object sender, EventArgs args)
{
    DataTable dt = null;
    CheckBox chk;
    foreach(GridViewRow gvrow in gvPR.Rows)
    {
        //chk = (CheckBox)(gvPR.Rows[i].Cells[0].FindControl("chkFru"));
        chk = (CheckBox)gvrow.FindControl("chkFru");
        if (chk.Checked == true)
        {
            dt = objCert.BuildCertInfo();
            DataRow dr = dt.NewRow();
            // HtmlInputHidden hdn = (HtmlInputHidden)(gvPR.Rows[i].Cells[0].FindControl("hdnFruId"));
            HtmlInputHidden hdn = (HtmlInputHidden)gvrow.FindControl("hdnFruId");
            string strFru = hdn.Value;
            dr[Certificate.SYS_SERIAL_NUMBER] = strFru;

            //get Fru info

            dsInfo = objCert.GetFruInfo(strFru);
            if (dsInfo == null)
            {
                setError(lblCertErr, Certificate.NO_SYS_INFO);
                return;
            }
            dr[Certificate.SYS_PART_ID] = dsInfo.Tables[0].Rows[0]["part_id"].ToString();
            dr[Certificate.SYS_PART_DESC] = dsInfo.Tables[0].Rows[0]["Part_desc"].ToString();
            dr[Certificate.SYS_SERIAL_NUMBER] = dsInfo.Tables[0].Rows[0]["Serial_Number"].ToString();
            dr[Certificate.LOC] = dsInfo.Tables[0].Rows[0]["Location"].ToString();
            dt.Rows.Add(dr);

        }

    }
   LoadWizStep2(dt); 
}

and the method for LoadWizStep2(dt) 和LoadWizStep2(dt)的方法

private void LoadWizStep2(DataTable dt)
{
    try
    {
        wizController.ActiveStepIndex = 1;
        GridView2.DataSource = dt;
        GridView2.DataBind();
        Session["FRU_INFO"] = dt;
    }
    catch (Exception ex)
    {
        throw ex;
    }

}

and this is code for aspx page 这是aspx页面的代码

 <table width="100%" cellpadding="0" cellspacing="0" style="background-color: White">
                <tr style="width: 100%">
                    <td colspan="2" align="left">
                        <asp:GridView ID="gvPR" runat="server" AutoGenerateColumns="False" GridLines="None"
                            CellSpacing="1" CellPadding="1"
                            Width="100%" BorderWidth="0px"
                            AllowSorting="True"
                            PageSize="30"
                            CssClass="data responsive"
                            OnSorting="gvPR_Sort" OnRowDataBound="ItemCellsUpdate"
                            EmptyDataText="No Certificates found" SortedAscendingHeaderStyle-CssClass="tableHeaderLink">
                            <Columns>
                                <asp:TemplateField>
                                    <HeaderTemplate>
                                         <asp:CheckBox ID="chkCerts" OnCheckedChanged="chkCerts_CheckedChanged"
                                                   AutoPostBack="true" runat="server" />
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkFru" OnCheckedChanged="chkFru_CheckedChanged" AutoPostBack="true" runat="server" /><input type="hidden" id="hdnFruId" runat="server"
                                            value='<%# DataBinder.Eval(Container.DataItem, "Fru") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="Fru" HeaderText="System Serial Number" SortExpression="Fru" />
                                <asp:BoundField DataField="SystemPartId" HeaderText="System Part Number" SortExpression="SystemPartId" />
                                <asp:BoundField DataField="SystemDesc" HeaderText="System Description" SortExpression="SystemDesc" />
                                <asp:BoundField DataField="Location" HeaderText="System Location" SortExpression="Location" />
                            </Columns>
                            <HeaderStyle Height="30px" HorizontalAlign="Center" />
                            <PagerSettings Visible="False" />
                        </asp:GridView>
                    </td>
                </tr>
            </table>

If checkbox is not checked i need to stop to go to next page .. how I can i fix this .... 如果未选中此复选框,则需要停止以转到下一页..我该如何解决此问题....

would any one please suggest ideas on this 任何人都可以对此提出建议吗

add a count and increment it inside 添加一个计数并在内部递增

int count=0
If(chk.checked)
{
count++
}

and

if(count>0)
{
//load step 2
}

You Will fine here more easy code 您可以在这里更简单的代码

int count=0;
            //ImageButton lbtn = (ImageButton)sender;
            DoctorDAO objDoctorDAO = new DoctorDAO();
            foreach (GridViewRow  row in grd_Data.Rows)
            {
                CheckBox chk = (CheckBox)grd_Data.Rows[row.RowIndex].FindControl("Chklist");
                if (chk.Checked == true)
                {

                    count++;

                }
            }
            if (count > 0)
            {
                foreach (GridViewRow row in grd_Data.Rows)
                {
                    CheckBox chk = (CheckBox)grd_Data.Rows[row.RowIndex].FindControl("Chklist");
                    if (chk.Checked == true)
                    {
                        ImageButton lbtn = (ImageButton)grd_Data.Rows[row.RowIndex].FindControl("btn_Delete");

                         objDoctorDAO.deleteDoctor(Convert.ToInt32(lbtn.CommandArgument));
                        lbl_Msg.Text = " Doctor Deleted Successfully!!";
                    }
                }
            }
            else
            {
                lbl_msg3.Text = "Please Check at least one record to Delete";
                return;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM