如果在中间选择了任何复选框并且未选择最后一个复选框,则复选框列表不应显示错误。 [英] checkbox list should not display error if any checkbox is seletected inbetween and if last one is not selected.

查看:87
本文介绍了如果在中间选择了任何复选框并且未选择最后一个复选框,则复选框列表不应显示错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用复选框列表,我有一个文本框,只为那些选择了相应复选框的行分配分数.i有一个循环,我正在检查每一行,如果选中复选框,如果选中,则只分配得分,否则我显示错误,请选择复选框!!这工作正常,但如果在中间说第一行和第五行复选框检查7个复选框...然后它仍然显示错误请选择复选框...我怎么能克服这个问题...编码如下:



Hi ,

I am using a list of checkbox and i am having a text box to assign scores to only those lines whoses corresponding checkbox is selected.. i have got a loop and i am checking each row if checkbox is checked and if checked then only assign score else i am displaying error as please select checkbox!! this works correctly but if inbetween say 1st row and 5th row checkbox is checked of the 7 checkboxes... then still it shows error please select checkbox... how can i overcome this issue... coding is as follows:

string maxcount = (hdgrdcount.Value);
int grdmaxcnt = Convert.ToInt32(maxcount);
con.Open();
if (txtassignscr.Text == "" || txtassignscr.Text == null)
{
    lblerrassign.Text = "Enter a score!";
}
else
{
    for (int i = 0; i < grdmaxcnt; i++)
    {
        TextBox gettxtscore = (TextBox)grdscore.Rows[i].FindControl("txtSetScore");
        bool isChecked = ((CheckBox)grdscore.Rows[i].FindControl("chkSelect")).Checked;
        Label refer = ((Label)grdscore.Rows[i].FindControl("refURL"));
        string refurl = refer.Text;
        if (isChecked)
        {
            gettxtscore.Text = txtassignscr.Text;
            string checkquery = "select score from tbl_Score where DataSourceId=''" + ddldatasource.SelectedItem.Value + "'' and ImportFileId=''" + ddltablename.SelectedItem.Value + "'' and ColumnName=''" + ddlcolumnname.SelectedValue + "'' and ColumnValue=''" + refurl + "'' and MMUserId=''" + Session["AdminId"] + "''";
            DataSet dscorexists = Main.BindGridSearch(checkquery);
            if (dscorexists.Tables[0].Rows.Count != 0 && dscorexists.Tables[0].Rows.Count != null)
            {
                string querynew = "update tbl_Score SET  Score=''" + gettxtscore.Text + "'' where DataSourceId=''" + ddldatasource.SelectedItem.Value + "'' and ImportFileId=''" + ddltablename.SelectedItem.Value + "'' and ColumnName=''" + ddlcolumnname.SelectedValue + "'' and ColumnValue=''" + refurl + "'' and MMUserId=''" + Session["AdminId"] + "''";
                if (Main.CommanDB(querynew) == 0)
                {
                    lblerrassign.Text = "Assigned values successfully!";
                }
            }
            else
            {
                string query = "INSERT INTO tbl_Score(DataSourceId,ImportFileId,ColumnName,ColumnValue,TrafficType,Score,MMUserId)VALUES (''" + ddldatasource.SelectedItem.Value + "'',''" + ddltablename.SelectedItem.Value + "'',''" + ddlcolumnname.SelectedValue + "'', ''" + refurl + "'','''', ''" + gettxtscore.Text + "'',''" + Session["AdminId"] + "'' )";
                SqlCommand cmd1 = new SqlCommand(query, con);
                cmd1.ExecuteNonQuery();
                lblerrassign.Text = "Assigned values successfully!";
            }
        }
        else
        {
            lblerrassign.Text = "Please select any checkbox!";
        }
    }
}





请帮助!!



提前感谢你!!



please help!!

thanking u in advance!!

推荐答案

错误可能就在这行:



The error is probably in this line:

bool isChecked = ((CheckBox)grdscore.Rows[i].FindControl("chkSelect")).Checked;





您是否检查过它是否真的找到了复选框?



您使用的是Web Forms吗?母版页?



另外,请不要连接字符串以发送到数据库:





Have you checked to see if it is actually finding the checkbox?

Are you using Web Forms? Master pages?

Also, please don''t concatenate strings to send to a database:

"select score from tbl_Score where DataSourceId=''" + ddldatasource.SelectedItem.Value 





使用参数化查询。它们并不困难,并且可以避免SQL注入攻击。



Use parameterized queries. They aren''t much more difficult and will save you from SQL Injection attacks.


我通过使用这样的标志解决了这个问题:



如果选中任何复选框标志== 1



那么显示错误信息时将检查标志== 1如果是,则没有错误信息否则

i显示错误消息。
I solved the issue by using flag like this:

If any checkbox checked flag == 1

then while displaying error message will check if flag== 1 if yes then no error message else
i am displaying error message.


这篇关于如果在中间选择了任何复选框并且未选择最后一个复选框,则复选框列表不应显示错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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