Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using the row data bound event in gridview. i have four records in gridview but when i am disply four records in label it display only first record four times. it does not execute the second and further records..
what is the problem ..
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");

            string s = "select id,title,user_id from document where category='" + drop_cat.SelectedItem.Value + "' and subctgry='" + 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)
            {
                x+= ds.Tables[0].Rows[0][1].ToString();
            }
            Label82.Text = x;
        }
    }


so, in the label first record display four times.... it does not execute 2nd and other..
whenevr row bound it only execute first..
Posted
Updated 29-Apr-12 20:39pm
v3
Comments
uspatel 30-Apr-12 2:28am    
share your code.....
summon_19 30-Apr-12 2:29am    
question not clear.
Please try to first make it clear

ds.Tables[0].Rows[0][1].ToString();

You have coded for what you are getting. You hardcoded for first row of your datatable.

Further, not sure what exactly you are trying to do but if you really want titles of all the rows of table, then loop through it and use loop index to access the row.
 
Share this answer
 
x= ds.Tables[0].Rows[0][1].ToString();

remove + sign

it will work
 
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