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 () ');
}
}
}