Control binding class

Source: Internet
Author: User

During development, some controls are often required to be bound after data is searched. The following are controls that we often need to bind during daily development. For more information, see the following code.

// Datalist

Public void dtlistbind <t> (datalist tmpdtlist, ilist <t> TMP ){
Tmpdtlist. datasource = TMP;
Tmpdtlist. databind ();
}

Protected void grvwbind <t> (gridview tmpgrvw, ilist <t> TMP ){
Tmpgrvw. datasource = TMP;
Tmpgrvw. databind ();
}

 

// Dropdownlist
Public void binddropdownlist <t> (dropdownlist tmpdrop, ilist <t> TMP, string idname, string name ){
Tmpdrop. datasource = TMP;
Tmpdrop. datatextfield = Name;
Tmpdrop. datavaluefield = idname;
Tmpdrop. databind ();

}

// Radiobuttonlist
Protected void bindradiobuttonlist <t> (radiobuttonlist tmpbtn, ilist <t> TMP, string idname, string name ){
Tmpbtn. datasource = TMP;
Tmpbtn. datatextfield = Name;
Tmpbtn. datavaluefield = idname;
Tmpbtn. databind ();
}

// ListBox

Protected void bindlistbox <t> (ListBox tmpctr, ilist <t> TMP, string idname, string name ){
Tmpctr. datasource = TMP;
Tmpctr. datatextfield = Name;
Tmpctr. datavaluefield = idname;
Tmpctr. databind ();
}

// Checkboxlist

Protected void bindcheckboxlist <t> (checkboxlist tmpctr, ilist <t> TMP, string idname, string name ){
Tmpctr. datasource = TMP;
Tmpctr. datavaluefield = idname;
Tmpctr. datatextfield = Name;

Tmpctr. databind ();
}

// Gridview
Protected void gridviewbind (gridview dbview, datatable table ){
Dbview. datasource = table;
Dbview. databind ();
}

 

// Datalist

Protected void listbind (system. Web. UI. webcontrols. datalist dblist, system. Data. datatable srctable ){
Dblist. datasource = srctable;
Dblist. databind ();
}

// Datatable

Protected void binddropdownlist (datatable tmptb, string str_text, string str_value, dropdownlist mydropdownlist ){
If (tmptb! = NULL ){
Datarow tmprow = tmptb. newrow ();
Mydropdownlist. datasource = tmptb. defaultview;
Mydropdownlist. datavaluefield = str_value;
Mydropdownlist. datatextfield = str_text;
Mydropdownlist. databind ();
}
Else {
Mydropdownlist. Items. Clear ();
}

}

 

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.