Double-click the value of the edit cell [Datagrid-webfrom]

Source: Internet
Author: User
datagrid|web| Cell thinking:

Adds a double-click event for each cell when the control is created and marks the row and column number of the cell.

When you double-click a cell, the row number of the cell and the column number are returned as parameters to the server.

The DataGrid is again bound to modify the value of the object cell.



Known problem: When the contents of a cell are enclosed in single quotes ('), the contents are not truncated. But this is not the case when you enter it later.


The tall man knows how to solve, please tell me.
E-mail:czhenq@163.com



. aspx file, add

Return line number, column number

function Dg_dbclick (Rowid,columnid)

{

Window. Form1.action= "dbclick.aspx" + "? Rowid= "+rowid+" &columnid= "+columnid;

Window. Form1.submit ();

}

Returns the modified text

function Txtcell_onchange ()

{

Window. Form1.ChangeText.value = window. Form1.txtCell.value;

}

Text Box KeyPress Event

function txtcell_onkeypress ()

{

//

}



. CS file

private void Page_Load (object sender, System.EventArgs e)

{

Place user code here to initialize page

if (! Page.IsPostBack)

{

Binddata ();

}

Else

{

Row ID

String RowID = request["RowID"] as String;

Column ID

String ColumnID = request["ColumnID"] as String;

Data in a text box

String str = request["Changetext"] as String;

Rebind with row and column IDs

if (RowID!= "" && ColumnID!= "" && str = "")

{

BINDDATA2 (int. Parse (RowID), Int. Parse (ColumnID));

}

Else

{

Update program

Label1.Text = str;

}

}

}



Re-bind a control after you double-click a cell

void BindData2 (int RowID, int ColumnID)

{

SqlConnection conn = new SqlConnection ("server=.;D Atabase=northwind;uid=sa;pwd=angel ");

SqlDataAdapter da = new SqlDataAdapter ("Select Customerid,companyname,contactname,contacttitle,address from Customers ", conn);

DataSet ds = new DataSet ();

Da. Fill (ds, "Customers");

DataTable dt = ds. Tables[0];

DataRow dr = dt. ROWS[ROWID];

String cellvalue = Dr[columnid]. ToString ();

Modify cell contents

Onblur Lose focus

onkeypress

OnChange

..................

String strText = "<input type=text id= ' Txtcell '

Onblur= ' Javascrite:txtcell_onblur ()

Onkeypress= ' javascript:txtcell_onkeypress () ');

}

}

}





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.