检索数据集列名称时出现问题 [英] problem in retrieving dataset column name
本文介绍了检索数据集列名称时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataSet dssa = (DataSet)Session["dt"];
string sr = dssa.Tables[0].Columns[2].ColumnName;
Response.Write(sr);
}
在此列中的名称显示3次.在这种情况下,我应该编写编码?
in this column name is displaying 3 times.in which event i should write the coding?
推荐答案
GridView1_RowDataBound
方法将对gridview中的每一行执行.因此,如果您有3行,则此方法将执行3次,因此Response.Write将发生3次.
一个简单的调试可能会导致这种情况. :)
GridView1_RowDataBound
method would get executed for every row in your gridview. Thus, if you have 3 rows then this method would be executed 3 times and thus Response.Write would happen 3 times.
A simple DEBUG could have led to this. :)
正如Sandeep所说,Response.Write在Rowdatabound事件中将发生3次.
如果不想三遍,只需放置一个标签控件即可获取列名.
或
在pageload事件中编写代码以获取列名.
As Sandeep said Response.Write will happen three times in Rowdatabound event.
If you don''t want it three times just place a label control to get the column name.
or
Write the code in pageload event to get the column name.
protected void Page_Load(object sender, EventArgs e)
{
DataSet dssa = (DataSet)Session["dt"];
string sr = dssa.Tables[0].Columns[2].ColumnName;
Response.Write(sr);
}
这篇关于检索数据集列名称时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文