B※N~『峰』 2021-01-21 16:38 采纳率: 0%
浏览 7

asp.net查询后点击表里的编辑页面跳转回原始表,求大神帮解决

    protected void Page_Load(object sender, EventArgs e)
    {
        //正常换行
        GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
        //下面这行是自动换行
        GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
       
        if (!IsPostBack)
          
        {
            this.TextBox4.Attributes.Add("onfocus", "javascript:WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',readOnly:true})");
            ViewState["search"] = null;
            LoadGridview();//加载表
        }

        
      

    }
 
private void LoadGridview()
    {
        
        string str = ConfigurationManager.ConnectionStrings["sqlconn"].ToString();
        using (SqlConnection con = new SqlConnection(str))
        {
            SqlCommand cmd = new SqlCommand("select * from wbx order by id desc", con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            this.GridView1.DataSource = ds.Tables[0].DefaultView;
            this.GridView1.DataBind();
            sda.Dispose();
           ds.Dispose();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ViewState["search"] = 1;
        LoadSearchGridview(TextBox2.Text);
    }
    private void LoadSearchGridview(string search)
    {

        string strSearch = null;
        if (TextBox2.Text != "无信息")
        {
            strSearch = "select * from wbx where 提交人='" + search + "' order by id desc";
        }
        sqlcon = new SqlConnection(strCon);
        sqlcon.Open();
        SqlDataAdapter adsa = new SqlDataAdapter(strSearch, sqlcon);
        DataSet adds = new DataSet();
        adsa.Fill(adds,"wbx");
        this.GridView1.DataSource = adds;
        this.GridView1.DataKeyNames = new string[] {  "提交人" };
        this.GridView1.DataBind();
        sqlcon.Close();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       
        GridView1.PageIndex = e.NewPageIndex;
        {
            if (ViewState["search"] == null)
            {
                LoadGridview();//加载表
            }
            else
            {
                LoadSearchGridview(TextBox2.Text); //加载查询后的表
            }
        }
        
      
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.Visible = true;
        GridView1.EditIndex= e.NewEditIndex;
        LoadGridview();
    }
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-29 17:34
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题