Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In the Below Code, If I set grd.AllowSorting = true then the code Block:
if (cell.Text == "Login")
{
  cell.Text = "TUSHAR";
}

is not executed.

And If I comment the code grd.AllowSorting = true
in that case the code
if (cell.Text == "Login")
{
  cell.Text = "TUSHAR";
}

is executed

It would be helpful if any one can tell why the cell.Text property is comming blank if i set allowsorting equal to true.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace RNDWeb
{
    public partial class GridViewRND : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {           
            BindDataUsingDataSet();
        }
        public void BindDataUsingDataSet()
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RNDLocal"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select ID,Login from users where login like 'survey%'", con);
            SqlDataAdapter dad = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            dad.Fill(ds);
            GridView grd = new GridView();
            grd.RowDataBound += GridView_RowDataBound;
            placeholder.Controls.Add(grd);
           grd.AllowSorting = true;
grd.DataSource = ds;
            grd.DataBind();
        }
        public void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex == 0)
            {
                e.Row.Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                foreach (TableCell cell in e.Row.Cells)
                {
 if (cell.Text == "Login")
                    {
                        cell.Text = "TUSHAR";
                    }
            }
        }
    }
}





Thanks in advance for your help
Regards
Tushar
Posted
Updated 17-Jan-11 20:03pm
v3
Comments
Ankur\m/ 18-Jan-11 4:47am    
Instead of adding an answer, use comments to discuss with the answerer for he is notified for your comment but not the answer.

Read last few comments in this below post.It may help you.

http://www.pederborg.dk/2007/01/25/changing-gridview-column-headertext-at-runtime/[^]
 
Share this answer
 
v2
Comments
Hiren solanki 18-Jan-11 5:29am    
Comment from OP:Thanks a lot Anupama
This worked for me
Anupama Roy 18-Jan-11 5:45am    
You are welcome!
hi
you can add new div control in client side.


after your GridView control add to div control in server side.
divControl.Controls.Add(grd);
 
Share this answer
 
Comments
Ankur\m/ 18-Jan-11 7:09am    
[moved from answer]OP wrote: Hi, Thanks for your reply, I am already using placeholder to add the gridview control. i.e. placeholder.Controls.Add(grd); Also tried to add div control in place of placeholder to add the gridview; but that didn't work either. It would be helpful if you can explain your solution, if you have tried my code. Your help would be appreciated Thanks Tushar

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