Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone...

In my web application.. i Have a database table with following values

---------------------------------------
Menu . . . . . . . . . Add Update level
----------------------------------------
ctl00_PartyPro....... 1 . . . 0 . . . 1
ctl00_EmpPro......... 1 . . . 0 . . . 1
ctl00_TransPro....... 0 . . . 1 . . . 1
ctl00_LoadMas........ 0 . . . 1 . . . 1
ctl00_UomMas........ 1 . . . 1 . . . 1
ctl00_ItemMas....... 1 . . . 1 . . . 1
ctl00_Invoice......... 0 . . . 1 . . . 1
ctl00_RptPrint........ 1 . . . 0 . . . 1
ctl00_ChkPwd........ 1 . . . 1 . . . 1
-----------------------------------

i need to retrieve this value to gridview,,

in that gridview i have 4 columns ,that columns like
Label1,Checkbox1,Checkbok2,Label2...


In this, that add and update column values if 1 means that check box should be checked, else it shouldnot be check...

i wrote cs code like below but it showing error..

C#
protected void Button3_Click(object sender, EventArgs e)
    {
        con.Open();
        string RR = "select Master,Canadd,CanUpdate,UserLevel FROM Tbl_Com_UserRights WHERE Userlevel='" + DDUserLvl.Text + "'";
            cmd = new SqlCommand(RR,con);
            dr = cmd.ExecuteReader();
            I1 = 0;
            while(dr.Read())
            {
                ((Label)(GridView1.Rows[I1].Cells[0].FindControl("Label1"))).Text = dr.GetString(0);
                ra = Convert.ToInt32(dr.GetValue(1));
                rb = Convert.ToInt32(dr.GetValue(2));
                if (ra == 1)
                {
                    ((CheckBox)(GridView1.Rows[I1].Cells[1].FindControl("CheckBox1"))).Checked = true;
                }
                else
                {
                    ((CheckBox)(GridView1.Rows[I1].Cells[1].FindControl("CheckBox1"))).Checked = false;
                }
                if (rb == 1)
                {
                    ((CheckBox)(GridView1.Rows[I1].Cells[2].FindControl("CheckBox2"))).Checked = true;
                }
                else
                {
                    ((CheckBox)(GridView1.Rows[I1].Cells[2].FindControl("CheckBox2"))).Checked = false;
                }
                ((Label)(GridView1.Rows[I1].Cells[0].FindControl("Label2"))).Text = dr.GetString(3);
                I1 = I1 + 1;
            }
            dr.Close();

       
    }


Am Getting the Following Error...


SQL
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index



is it possible to get solution.. plz help me....
Posted
Updated 19-Aug-12 20:54pm
v2
Comments
ridoy 20-Aug-12 2:26am    
Which error you get..please share
Raajendran 20-Aug-12 2:55am    
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
_Amy 20-Aug-12 2:27am    
You forgot to ask the actual question. What is that?
Raajendran 20-Aug-12 2:57am    
error is

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

how to combine that numeric value with checkbox checked value...
_Amy 20-Aug-12 3:00am    
Which line?

As the question is not so clear you can get some help here[^], many similar questions results you can get.
 
Share this answer
 
Sounds like a fresher...have a look on Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List[^]...This will give you a clear insight for your needs.
 
Share this answer
 
Comments
Raajendran 20-Aug-12 2:28am    
Thank U So Much Prabakaran...

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