Click here to Skip to main content
14,698,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have a gridview in which i add the check box, on button click i have show the alert message that "u have selected the same value twice" . i am unable to this task i have use loop but cant able to match the value using check box.

ignore the bracket

for (int i = 0; i < rowcount - 1; i++)
string Breaktype1= popgvdetails.Rows[j].Cells[6].Text;
CheckBox checklist = (CheckBox)popgvdetails.Rows[i].FindControl("popcheck");
 if (checklist.Checked == true)

for (int j = 0; j < rowcount - 1; j++)
 if (i != j)
string Breaktype2 = popgvdetails.Rows[j].Cells[6].Text;

                        if (Breaktype1 == Breaktype2)
                            ClientScript.RegisterStartupScript(this.GetType(), "disExp", "<script> alert('You have select the same Break Type');</script>");
}<pre lang="c#">


1 solution

Now,I give some code ,as follows :

protected void Button1_Click(object sender, EventArgs e)
           int count = 0;
           string items = "";
           foreach (GridViewRow item in GridView1.Rows)
               CheckBox cb = (CheckBox)item.FindControl("CheckBox2");
               if (cb.Checked)
                   items = items + item.Cells[1].Text;//
           Response.Write(count.ToString() + items);
Ravimcts 25-Jul-13 22:58pm
@Chui PuiKwan- but i cant show the duplicate value
Chui PuiKwan 25-Jul-13 23:17pm
so ,you first get your selected index ,and store them in viewstate .
when you click again ,query viewstate and if viewstate exist the index ,you can alert warn .
Ravimcts 25-Jul-13 23:20pm
it can be done through array? if yes then give me some hint...!
Chui PuiKwan 26-Jul-13 1:59am
if you want to do it by array .
you can implement it by using a global array .
such as :
static String[] existIndexArr=new String[1];
if click first:existIndexArr[0]=index;
if click second:query the array

notes that viewstate is store data in client
and array can store data in server .
Ravimcts 26-Jul-13 6:33am
k.. thnx but i cnt use viewstate just because of security purpose well.. thnx i got it .
d query is sloved by me

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