GridView绑定数据

gexuehui 2013-12-10 07:55:43
.Net的GridView数据绑定后(GridView有did,dname,dedit这几列),要哪一行的dname是等于“xx”的,那么就让dedit.Enable=false,否则,就是true。请问这个怎么实现?
我写了如下的代码,但是,不知道为什么,uname_temp=“”,可是在页面上明明有数据的
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
ListBind();
}
string uname = Convert.ToString(Application.Get("UserName"));
for (int i = 0; i < GridView1.Rows.Count; i++)
{
int i_lastindex = GridView1.Columns.Count - 1;
string uname_temp = GridView1.Rows[i].Cells[1].Text;
if (uname_temp == uname)
{
GridView1.Rows[i].Cells[i_lastindex].Enabled = true;
}
else
{
GridView1.Rows[i].Cells[i_lastindex].Enabled = false;
}

}
}
...全文
10499 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mala_441911705 2014-06-16
  • 打赏
  • 举报
回复
:GridView绑定商品详细信息 public partial class MemberManage_GoodsInfo : System.Web.UI.Page { SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); protected void Page_Load(object sender, EventArgs e) { string sqlstr = "select * from tbPicture"; //创建执行查询操作的SQL语句 sqlcon.Open();//打开数据库连接 SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);//创建数据阅读器 DataSet myds = new DataSet(); //创建数据集 myda.Fill(myds); //填充数据集 gvGoodsInfo.DataSource = myds; //设定数据源 gvGoodsInfo.DataBind(); //绑定数据 sqlcon.Close(); //关闭数据库连接 } 二、处理绑定 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { sqlconn.Open();//打开数据库连接 string strid = Page.Request.QueryString["GoodsID"];//接收页面传值 string sqlstr = "select * from tbPicture where PicId='" + strid + "'";//创建查询语句 SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn); DataSet myds = new DataSet(); myda.Fill(myds, "tbPicture");//CodeGo.net/ DataRowView mydrv = myds.Tables["tbPicture"].DefaultView[0];//创建表视图DataRowView txtGID.Text = Convert.ToString(mydrv.Row["PicId"]); txtGName.Text = Convert.ToString(mydrv.Row["PicName"]); txtGType.Text = Convert.ToString(mydrv.Row["PicType"]); txtGStore.Text = Convert.ToString(mydrv.Row["GoodsStock"]); txtGPrice.Text = Convert.ToString(mydrv.Row["SellNumber"]); txtGIntro.Text = Convert.ToString(mydrv.Row["PicName"]) + "…"; iGPhoto.ImageUrl = Convert.ToString(mydrv.Row["PicPath"]); } }
KJ_Wang 2014-05-26
  • 打赏
  • 举报
回复
GridView1_RowDataBound肯定行的,多试试,人家说过了!
沐沐坏小孩 2014-01-02
  • 打赏
  • 举报
回复
引用 6 楼 junlinfushi 的回复:
[quote=引用 3 楼 bdmh 的回复:]

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
+1[/quote] +1
junlinfushi 2013-12-10
  • 打赏
  • 举报
回复
引用 3 楼 bdmh 的回复:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
+1
bu_ge 2013-12-10
  • 打赏
  • 举报
回复
你确定string uname_temp = GridView1.Rows[i].Cells[1].Text; 你要提取的是第二列的值
hello_code_com 2013-12-10
  • 打赏
  • 举报
回复
引用 3 楼 bdmh 的回复:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
正解
bdmh 2013-12-10
  • 打赏
  • 举报
回复

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "xxx")
            {
                设置是否可编辑
            }
    }
bdmh 2013-12-10
  • 打赏
  • 举报
回复
在rowbound事件中处理

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧