• Gridivew里的Textbox值取不出来?


    以前做东西时没发现过这个问题,因为以前做的都是用的gridview自己提供的按钮,没有自己加上的.

    今天做东西加了几个排序的按钮.

    处理这个两个按钮的事件如下:

     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "up")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                Cfitn.Model.SChannel channel = Cfitn.BLL.SChannelCode.GetChannel(id);
                Cfitn.BLL.SChannelCode.ChannelUp(channel);
                Response.Write("<script language='javascript'>alert('前置成功!');</script>"); 
            }
            if (e.CommandName == "down")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                Cfitn.Model.SChannel channel = Cfitn.BLL.SChannelCode.GetChannel(id);
                Cfitn.BLL.SChannelCode.ChannelDown(channel);
                Response.Write("<script language='javascript'>alert('后置成功!');</script>");
            }

              gvBind();//数据绑定

    }

    然后更新时命令如下:

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string strurl= ((DropDownList)GridView1.Rows[e.RowIndex].Cells[2].FindControl("ddlUrl")).SelectedValue;
            string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
            int numhit = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim());
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
            Cfitn.Model.SChannel channel = Cfitn.BLL.SChannelCode.GetChannel(id);
            channel.Vc2URL = strurl;
            channel.NumClick = numhit;
            channel.Vc2ChannelName = name;
            Cfitn.BLL.SChannelCode.UpdateChannel(channel);
            Response.Write("<script language='javascript'>alert('修改成功!');</script>");
            GridView1.EditIndex = -1;
            gvBind();
        }

     

    可是执行的时候就出现问题了,数据修改了,也提示成功了,可就是数据没有更新.

    最后开始找问题,是不是!Page.ispostback没写,可查看了一下Page_load 也写了呀,想来想去一定是什么地方把数据重新绑定了一次.最后终于发现了.原来不论是自己添加的按钮还是gridview自带的按钮.它都要响应RowCommand事件.

     

    所以这个问题的解决办法就是:RowCommand里的数据绑定事件,分别写入到两个if语句里去

  • 相关阅读:
    使用pynlpir增强jieba分词的准确度
    graph easy绘制ascii简易流程图
    kubernetes版本融合解决方案
    设计的一些kubernetes面试题目
    使用go-template自定义kubectl get输出
    docker、oci、runc以及kubernetes梳理
    启动docker容器时的Error response from daemon: devmapper: Error mounting: invalid argument. 错误解决
    kubernetes endpoint一会消失一会出现的问题剖析
    docker启动容器报错: could not synchronise with container process: not a directory
    docker中执行sed: can't move '/etc/resolv.conf73UqmG' to '/etc/resolv.conf': Device or resource busy错误的处理原因及方式
  • 原文地址:https://www.cnblogs.com/wenming205/p/1260872.html
Copyright © 2020-2023  润新知