Click the edit link in the gridview control and send this line of data to the editing interface for modification.

Source: Internet
Author: User

The front-end design is as follows:

The "edit" column is what we are talking about today. Click the edit link to load the data in the row of the gridview control to the Edit page. Then, you can modify the data. Edit a column. The foreground code example is as follows:

<Asp: templatefield headertext = "edit" runat = "server"> <itemtemplate> <asp: linkbutton id = "linkbuttonupdate" commandname = "cmdupdate" runat = "server" commandargument = '<% # eval ("ID") + "," + eval ("name ") + "," + eval ("tname") + "," + eval ("ip") + "," + eval ("Port") + ", "+ eval (" time ") +", "+ eval (" location ") +", "+ eval (" Misc ") %> '> edit </ASP: linkbutton> </itemtemplate> </ASP: templatefield>

The Edit link property commandargument has multiple parameters, which are actually the values of each column in The gridview control. Use the rowcommand event of the gridview control to upload the value to the editing interface.

/// <Summary> /// obtain the row of the current data in the gridview /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void gridview_rowcommand (Object sender, gridviewcommandeventargs e) {If (E. commandname. equals ("cmdupdate") {string [] estr = E. commandargument. tostring (). split (','); string id = convert. tostring (estr [0]); string name = convert. tostring (estr [1]); string tname = convert. tostrin G (estr [2]); string IP = convert. tostring (estr [3]); string port = convert. tostring (estr [4]); string time = convert. tostring (estr [5]); string location = convert. tostring (estr [6]); // string installtime = convert. tostring (estr [6]); string MISC = convert. tostring (estr [7]); response. redirect ("modify_registration.aspx? Id = "+ ID +" & name = "+ name +" & tname = "+ tname +" & IP = "+ IP +" & Port = "+ port + "& time = "+ time +" & location = "+ location +" & MISC = "+ MISC, false );}}

The above code is to bind the row data value of the gridview control to the background, jump through response. Redirect () and then upload the value to each control on the editing page. You need to load the uploaded data in the page_load () method of the background code on the editing page,

protected void Page_Load(object sender, EventArgs e)        {            if (!Page.IsPostBack)            {                if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString().Trim() != "")                {                    this.txtid.Text = Request.QueryString["id"].ToString().Trim();                    this.txtname.Text = Request.QueryString["name"].ToString().Trim();                    this.DropDownList_tname.Text = Request.QueryString["tname"].ToString().Trim();                    this.txtip.Text = Request.QueryString["ip"].ToString().Trim();                    this.txtport.Text = Request.QueryString["port"].ToString().Trim();                    this.txttime.Text = Request.QueryString["time"].ToString().Trim();                    this.txtlocation.Text = Request.QueryString["location"].ToString().Trim();                    //this.Calendarinstalltime.NextMonthText = Request.QueryString["installtime"].ToString().Trim();                    this.txtmisc.Text = Request.QueryString["misc"].ToString().Trim();                }                BindData_TypeName();            }        }

For example, if you click the data row numbered "19", the editing page displays the following results,

This is what we are talking about today. After passing the value, you can change it as needed and update the data to the background database...

For reference only !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.