Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
DataSet dssa = (DataSet)Session["dt"];
        string sr = dssa.Tables[0].Columns[2].ColumnName;
        Response.Write(sr);
}


in this column name is displaying 3 times.in which event i should write the coding?
Posted
Updated 7-Feb-11 20:09pm
v3

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. :)
 
Share this answer
 
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);
        }
 
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