Click here to Skip to main content
14,640,651 members
Rate this:
Please Sign up or sign in to vote.
See more:
I AM USING GRIDVIEW. THERE IS 3 COLUMN.E.G. FIRST IS CHECKBOX THEN NAME THEN ADDRESS.

CHECKBOX CHECKED FROM THE VALUE OF ANOTHER TABLE AND OTHER TWO FIELDS COME FROM FIRST TABLE. I ALSO WANT TO DISPLAY ALL RECORDS FROM THE FIRST TABLE.

I WANT THAT .........
IF I SELECT THE NAME FROM DROPDOWN LIST AND IF ITS VALUE TRUE FROM OTHER TABLE IS AUTOMATICLY CHECKED. AND ALSO I WANT DISPLAY OTHER DATA IN GRID FROM FIRST TABLE AND ITS VALUE FOR CHECKBOX FALSE IF IT IS NOT MATCH...


SOOO, IN SORT I WANT TO CHECKBOX CHECKED TRUE IF MATCH AND FALSE IF IT NOT MATCH AND DISPLAY ALL RECORDS FROM FIRST TABLE..

CODE WHICH I HAVE USE :

protected void Button1_Click1(object sender, EventArgs e)
    {
        String xxx = "";
        Button2.Visible = true;
        Panel1.Visible = true;

        string s = "select document_id,user_id from document_rights where user_id='" + drop_user.SelectedItem.Value + "' and category='" + drop_cat.SelectedItem.Value + "' and sub_cat='" + drop_sub_cat.SelectedItem.Value + "'";
        SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
        DataSet ds = new DataSet();
        ad.Fill(ds);

        if (ds.Tables[0].Rows.Count != 0)
        {
            xxx = ds.Tables[0].Rows[0][0].ToString();
            string[] split = xxx.Split(',');
            intArray1 = new int[split.Length];
            for (int i = 0; i < split.Length; i++)
            {
                intArray1[i] = System.Convert.ToInt32(split[i]);

            }

            string xxxx = "select id,title from document where id in(";
            for (int k = 0; k < intArray1.Length; k++)
            {
                xxxx += intArray1[k] + ",";
            }
            xxxx = xxxx.Substring(0, xxxx.Length - 1) + ") and category='" + drop_cat.SelectedItem.Value + "' and subctgry='" + drop_sub_cat.SelectedItem.Value + "' ";
       
            string xxxx1 = "SELECT DISTINCT document.user_id, document.id, document_rights.bit_indicator, document.title FROM  document CROSS JOIN  document_rights where document.category='" + drop_cat.SelectedItem.Value + "' and document.subctgry='" + drop_sub_cat.SelectedItem.Value + "'";
            SqlDataAdapter ad1 = new SqlDataAdapter(xxxx1, c.getcon());
            DataSet ds1 = new DataSet();
            ad1.Fill(ds1);

            if (ds1.Tables[0].Rows.Count != 0)
            {
                foreach (GridViewRow di in GridView1.Rows)
                {
                    
                    CheckBox chkBx = (CheckBox)di.FindControl("CheckBox1");
                    //if (chkBx.Checked==false)
                    //{
                        //int i=1;
                        //string s11="Select bit_indicator from document_rights where user_id='"+drop_user.SelectedItem.Value+"' and bit_indicator='"+i+"'";
                        //SqlDataAdapter ad2 = new SqlDataAdapter(s11, c.getcon());
                        //DataSet ds2 = new DataSet();
                        //ad2.Fill(ds2);
                        //if (ds2.Tables[0].Rows.Count != 0)
                        //{
                        //    chkBx.Checked = true;
                        //}
                    //}
                }
            }
            //ds.Merge(ds1, false, MissingSchemaAction.Add);
            GridView1.DataSource = ds1;
            GridView1.DataBind();
        }

        //GridView1.DataSource =c.getdata("SELECT DISTINCT document.user_id, document.id, document_rights.bit_indicator, document.title FROM  document CROSS JOIN  document_rights where document.category='"+drop_cat.SelectedItem.Value+"' and document.subctgry='"+drop_sub_cat.SelectedItem.Value+"'");
        //GridView1.DataBind();
        //SqlDataAdapter ad = new SqlDataAdapter("SELECT document.user_id, document.id, document_rights.bit_indicator FROM document INNER JOIN document_rights ON document.user_id = document_rights.user_id", c.getcon());
        //DataSet ds = new DataSet();
        //ad.Fill(ds);

        ////SqlDataAdapter ad1 = new SqlDataAdapter("select bit_indicator from document_rights where category='" + drop_cat.SelectedItem.Text + "' and sub_cat='" + drop_sub_cat.SelectedItem.Text + "'", c.getcon());
        ////DataSet ds1 = new DataSet();
        ////ad1.Fill(ds1);
        ////ds.Merge(ds1);

        //GridView1.DataSource = ds;
        //GridView1.DataBind();
    }

please help me...
Thankss in advance...
Mitesh
Posted
Updated 26-Apr-12 18:01pm
v2
Comments
Lakamraju Raghuram 27-Apr-12 0:19am
   
The text in all capitals is irritating to read. Change it please
John d. Bartels 13-May-12 13:33pm
   
This question is worded poorly. I am unable to decode what you want to accomplish with the checkboxes. Being able to automatically select the checkbox if the value for the item is set to true in the first table shouldn't be an issue. That part I understood, but the following made no sense to me: "AND ALSO I WANT DISPLAY OTHER DATA IN GRID FROM FIRST TABLE AND ITS VALUE FOR CHECKBOX FALSE IF IT IS NOT MATCH...


SOOO, IN SORT I WANT TO CHECKBOX CHECKED TRUE IF MATCH AND FALSE IF IT NOT MATCH AND DISPLAY ALL RECORDS FROM FIRST TABLE..
"

I think some screenshots and better wording for this question will help you get an answer much sooner...

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100