Summary of the use of ASP. GridView control

Source: Internet
Author: User

1: Data binding

GridView supports data-binding data source formats, for example, you can use ObjectDataSource to bind data sources.

Dataset,datatable,list<t>, etc.

2: Column Binding

1) boundfield--generally directly binds the field corresponding to the data source, by specifying DataField to implement the binding.

2) checkboxfield--when the GridView control needs to present a CheckBox control, it is also bound to a bool type field by DataField.

3) hyperlinkfied--bound column implements hyperlink function, datanavigateurlfields= "ID" datanavigateurlformatstring= "xxx.aspx?id{0}"

4) ImageField,

5) ButtonField,

6) commandfield--command row and column template, built-in additions and deletions, selection and other functions (no specific use)

7) TemplateField--more flexible, generally by editing the column template can achieve the functions we need.

3:gridview-onrowdatabound Events

With this event we can specify a series of actions such as events for the bound columns

protected void Fslgridview1_rowdatabounding (object sender, GridViewRowEventArgs e)

{if (E.row.rowtype = = Datacontrolrowtype.datarow)

{

System.Data.DataRowView dv = (System.Data.DataRowView) E.row.dataitem;

String id = dv["id"]. ToString ();

Button btncheck = (button) E.row.findcontrol ("Btncheck");

Button Btnlook = (button) E.row.findcontrol ("Btnlook");

BTNCHECK.ATTRIBUTES.ADD ("onclick", "changevalue" + Btncheck.clientid + "', '" + ID + "'); return false");

}

}

4:gridview-onrowcommand Events

When we specify Commandname= "Linkdel" commandargument= ' <% #Eval ("ID")%> ' parameters for the controls inside the template column,

This event is triggered when we manipulate these controls. protected void Fslgridview2_rowcommand (object sender, Gridviewcommandeventargs e)
{
if (E.commandname = = "Linkdel")
{
if (e.commandargument = = null)
{
Return
}
String ID = E.commandargument.tostring ();
EVALUATEDATABLL BLL = new EVALUATEDATABLL ();
if (BLL. Deleterowdatabyid (ID))
{
Framework.Assistant.Web.ClientScriptHelper.WriteAlert ("Success", "Delete succeeded!") ");
Framework.Assistant.Web.ClientScriptHelper.RegisterScript ("Close", "CloseWindow (True);");
}
Else
{
Framework.Assistant.Web.ClientScriptHelper.WriteAlert ("Failure", "Delete failed, please correct and then re-operate!") ");
}
}
}

5:girdview the traversal of a control

foreach (GridViewRow item in this.) Fslgridview1.rows)
{
Todo:the things you want to do
}

6: Formatted Display of columns

<asp:templatefield headertext= "Content
<itemstyle width= "15%" horizontalalign= "Center"/>
<ItemTemplate>
<%# decryptinfocontent (Eval ("Infocontent"). ToString ())%>
</ItemTemplate>
</asp:TemplateField>

decryptinfocontent--Page Background method

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.