The DataGrid RequiredFieldValidator control is used to verify whether a value is entered in an input box, and the RegularExpressionValidator control is used for regular expressions. See other information for instructions on regular expressions.
Where the ControlToValidate property is the ID number of the text box that needs to be validated. The text in the label is the prompt displayed when the checksum is unsuccessful, and the display property is the way of displaying the message.
The contents of the <Columns> tags in the DataGrid are the columns of the DataGrid, and the columns can also be added to the template column, which corresponds to each template column and can have <itemtemplate>,<edititemtemplate >,<HeaderTemplate>,<FooterTemplate> a few tags, where <ItemTemplate> is the DataGrid in the normal display when the column of the label,< Edittemplate> is also the style of the DataGrid column in the editing state.
In these tags we can insert the control and then use Datagrid1.item[i in the background code. FindControls ("Coltrol Name") can manipulate controls in the DataGrid.
To control the state of the DataGrid containing controls when Datageid is in edit state, we can use CSS style definitions to add the following code to the
<style type= "Text/css" >.mytextbox {border-right: #000000 1px solid; Border-top: #000000 1px solid; font-size:9pt; Border-left: #000000 1px solid; width:80px; Border-bottom: #000000 1px solid; height:20px}
</style>
Here only a part of the code, such as the need for complete code, please write to obtain. Cheaper_c@sina.com
----------------------------------------------------------Below is the run-time screen map-----------------------------------------
------------------------------------------------part of the background code---------------------------------------------------------
Private new void DataBind ()
{
DataBind ("au_fname");
}
Overloaded DataBind () method to facilitate sorting in DataGrid
private void DataBind (string sortfield)
{
ds = new DataSet ();
da = new SqlDataAdapter ("select * from Authors_new", conn);
Da. Fill (ds, "authors");
DataView Source = ds. tables["Authors"]. DefaultView;
Source. Sort = SortField;
DataGrid1.DataSource = source;
Datagrid1.databind ();
SqlDataAdapter ddl_da = new SqlDataAdapter ("Select DISTINCT State from Authors_new", conn);
Ddl_da. Fill (ddl_table);
Regclientscript ();
}
This method refers to the article "Add All selected CheckBox controls on the DataGrid header" by Brother Vzxq
Original address: Http://blog.csdn.net/vzxq/archive/2004/09/13/103156.aspx
private void Regclientscript ()
{
For Datagrid1.controls[0], you can refer to another article by Brother Vzxq
Http://blog.csdn.net/vzxq/archive/2004/09/13/103167.aspx
foreach (DataGridItem item in Datagrid1.controls[0]. Controls)
{
if (item. ItemType = = Listitemtype.header)
{
CheckBox chkall= (CheckBox) item. FindControl ("Chkall");
System.Text.StringBuilder strscript = new System.Text.StringBuilder ("<script language= ' javascript ' > \ \");
Strscript.append ("function checkstatus () {\ n");
Strscript.append ("var bAll = true; \ n ");
Strscript.append ("BAll = document.all (' + Chkall.clientid +"). Checked; \ n ");
for (int i=0; i<datagrid1.items.count; i++)
{
Strscript.append ("document.all" + datagrid1.items[i). Cells[0]. FindControl ("CheckBox1"). ClientID + "'). Checked = BAll; \ n ");
}
Strscript.append ("} \ n");
Strscript.append ("</script> \ n");
if (! Page.isclientscriptblockregistered ("CheckStatus"))
Page.registerclientscriptblock ("CheckStatus", strscript.tostring ());
CHKALL.ATTRIBUTES.ADD ("onclick", "checkstatus ()");
Break
}
}
}
Server-side functions that are triggered when the "edit" button is clicked
Set the panel's Visible property to false first because controls in the cell (such as a TextBox) will be Datageid when the DataGrid is in edit state
It's not easy to squeeze into the panel where we add records.
public void Grid_edit (object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Panel1.visible = false;
Datagrid1.edititemindex = (int) E.item.itemindex;
DataBind ();
System.Web.UI.WebControls.DropDownList ddl_state = (DropDownList) datagrid1.items[(int) E.item.itemindex]. FindControl ("Edit_