将alloworting设置为true时,网格的Cell.Text属性为空白 [英] Cell.Text property of grid is blank when allowsorting is set to true

查看:102
本文介绍了将alloworting设置为true时,网格的Cell.Text属性为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在下面的代码中,如果我设置了grd.AllowSorting = true,则代码块:

Hi,
In the Below Code, If I set grd.AllowSorting = true then the code Block:

if (cell.Text == "Login")
{
  cell.Text = "TUSHAR";
}


未执行.

如果我注释代码grd.AllowSorting = true
在这种情况下,代码


is not executed.

And If I comment the code grd.AllowSorting = true
in that case the code

if (cell.Text == "Login")
{
  cell.Text = "TUSHAR";
}


被执行

如果我将alloworting设置为true,那么任何人都可以说出cell.Text属性为何为空白将很有帮助.


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.

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";
                    }
            }
        }
    }
}






预先感谢您的帮助
问候
Tushar






Thanks in advance for your help
Regards
Tushar

推荐答案

阅读下面这篇文章的最后几条评论,可能会对您有所帮助.

http://www.pederborg.dk/2007/01/25 /changing-gridview-column-headertext-at-runtime/ [
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/[^]



您可以在客户端添加新的div控件.
hi
you can add new div control in client side.



将GridView控件添加到服务器端的div控件之后.
divControl.Controls.Add(grd);



after your GridView control add to div control in server side.
divControl.Controls.Add(grd);



http:///msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.gridview.sorting.aspx

http://www.dotnetjohn.com/articles.aspx?articleid=53
Hi
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx

http://www.dotnetjohn.com/articles.aspx?articleid=53


这篇关于将alloworting设置为true时,网格的Cell.Text属性为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆