Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!!
Posted

The error is probably in this line:

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


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 


Use parameterized queries. They aren't much more difficult and will save you from SQL Injection attacks.
 
Share this answer
 
Comments
Shruthi.BT 21-Mar-13 10:29am    
yes.. it is finding the checkbox and yes.. i am using master pages... any help for this issue please.. !!
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900