qq_49868769
B※N~『峰』
2021-01-21 16:38

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

  • c语言
  • asp.net
  • visual studio
    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();
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答