gridview中的行数据绑定事件 [英] row data bound event in gridview
问题描述
我在gridview中使用行数据绑定事件。我在gridview中有四条记录但是当我在标签中显示四条记录时,它只显示四次第一条记录。它没有执行第二个和更多的记录..
有什么问题..
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 ..
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;
}
}
所以,在标签第一条记录中显示四次......它没有执行第二个和其他..
whenevr行绑定它只执行第一个..
so, in the label first record display four times.... it does not execute 2nd and other..
whenevr row bound it only execute first..
推荐答案
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.
x = ds.Tables [0] .Rows [0] [1] .ToString();
删除+符号
它将起作用
x= ds.Tables[0].Rows[0][1].ToString();
remove + sign
it will work
这篇关于gridview中的行数据绑定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!