Some common controls are bound to the. NET data control. To operate these controls, we need to write code to find the control ID. Generally, it cannot be searched by ID. Now I will summarize how to use it.
The Code is as follows:
View plaincopy to clipboardprint?
Protected void rptpaper_itemdatabound (Object sender, repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
ListBox lB = (ListBox) E. Item. findcontrol ("listbox1"); // ListBox
// Panel panelshowtext = (panel) E. Item. findcontrol ("panelshowtext ");
// Panel panelimgshow = (panel) E. Item. findcontrol ("panelimgshow ");
// Image imgshow = (image) E. Item. findcontrol ("imgshow"); // Image
// String qid = (datarowview) E. Item. dataitem). Row ["ID"]. tostring (); // datarowview is the ID of the repeater
// String strsql = "select * From radiotable where id = '" + qid + "'";
// Datatable dt = dtdb. getdatatable (strsql );
// If (Dt. Rows. Count> 0)
//{
// Determine whether a graph exists
// String imgpath = DT. Rows [0] ["imgpath"]. tostring ();
// If (imgpath = NULL | imgpath = "")
//{
// Panelimgshow. Visible = false;
// Panelshowtext. Visible = true;
//}
// Else
//{
// Panelshowtext. Visible = false;
// Panelimgshow. Visible = true;
// Imgshow. imageurl = "~ /Upfile/"+ imgpath;
//}
// Tbcontent. Text = DT. Rows [0] ["qtitle"]. tostring ();
// String Ss = DT. Rows [0] ["qcontent"]. tostring ();
// String qfeng = DT. Rows [0] ["qfeng"]. tostring ();
/// String
// String [] Sarr = ss. Split ('| ');
// String [] sarrqfeng = qfeng. Split ('| ');
// Radlist. Items. Clear ();
// For (INT I = 0; I <(Sarr. Length-1); I ++)
//{
// Radlist. Items. Add (New listitem (Sarr [I]. tostring (). Trim (), sarrqfeng [I]. tostring (). Trim ()));
/// Lblfeng. Text + = sarrcx [I]. tostring (). Trim ();
/// Radlist. Items = "styled ";
//}
//}
// DT. Dispose ();
// Radlist. datasource =
}
}
Protected void rptpaper_itemdatabound (Object sender, repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
ListBox lB = (ListBox) E. Item. findcontrol ("listbox1"); // ListBox
// Panel panelshowtext = (panel) E. Item. findcontrol ("panelshowtext ");
// Panel panelimgshow = (panel) E. Item. findcontrol ("panelimgshow ");
// Image imgshow = (image) E. Item. findcontrol ("imgshow"); // Image
// String qid = (datarowview) E. Item. dataitem). Row ["ID"]. tostring (); // datarowview is the ID of the repeater
// String strsql = "select * From radiotable where id = '" + qid + "'";
// Datatable dt = dtdb. getdatatable (strsql );
// If (Dt. Rows. Count> 0)
//{
// Determine whether a graph exists
// String imgpath = DT. Rows [0] ["imgpath"]. tostring ();
// If (imgpath = NULL | imgpath = "")
//{
// Panelimgshow. Visible = false;
// Panelshowtext. Visible = true;
//}
// Else
//{
// Panelshowtext. Visible = false;
// Panelimgshow. Visible = true;
// Imgshow. imageurl = "~ /Upfile/"+ imgpath;
//}
// Tbcontent. Text = DT. Rows [0] ["qtitle"]. tostring ();
// String Ss = DT. Rows [0] ["qcontent"]. tostring ();
// String qfeng = DT. Rows [0] ["qfeng"]. tostring ();
/// String
// String [] Sarr = ss. Split ('| ');
// String [] sarrqfeng = qfeng. Split ('| ');
// Radlist. Items. Clear ();
// For (INT I = 0; I <(Sarr. Length-1); I ++)
//{
// Radlist. Items. Add (New listitem (Sarr [I]. tostring (). Trim (), sarrqfeng [I]. tostring (). Trim ()));
/// Lblfeng. Text + = sarrcx [I]. tostring (). Trim ();
/// Radlist. Items = "styled ";
//}
//}
// DT. Dispose ();
// Radlist. datasource =
}
}
This is to be searched in repeater. When searching outside the Repeater control.
The Code is as follows:
View plaincopy to clipboardprint?
Protected void btnrest_click (Object sender, eventargs E)
{
For (INT I = 0; I <this. rptpaper. Items. Count; I ++)
{
ListBox LB2 = (ListBox) This. rptpaper. items [I]. findcontrol ("listbox2 ");
Lb2.items. Clear ();
}
Buildpaper ();
}
Protected void btnrest_click (Object sender, eventargs E)
{
For (INT I = 0; I <this. rptpaper. Items. Count; I ++)
{
ListBox LB2 = (ListBox) This. rptpaper. items [I]. findcontrol ("listbox2 ");
Lb2.items. Clear ();
}
Buildpaper ();
}
Of course, you can use the following method for button events in repeater:
View plaincopy to clipboardprint?
··· · 50 ······· · 90 ····· · 140 · 150
Protected void rptcontact_itemcommand (Object source, repeatercommandeventargs E)
{
If (E. commandname = "delete ")
{
Long contid = convert. toint64 (E. commandargument. tostring ());
Deletecontact (contid );
Databindcontact ();
}
}
Protected void rptcontact_itemcommand (Object source, repeatercommandeventargs E)
{
If (E. commandname = "delete ")
{
Long contid = convert. toint64 (E. commandargument. tostring ());
Deletecontact (contid );
Databindcontact ();
}
}
This is a common button event. There are many details on the Internet.
I will not mention it more here. I will mainly introduce some of the buttons in repeater that are not designated by the button event. For example, the selectedindexchanged event in ListBox. This event does not need to be written in itemcommand in repeater. It is the same as writing this event.
The Code is as follows:
View plaincopy to clipboardprint?
Protected void listbox1_selectedindexchanged (Object sender, eventargs E)
{
For (INT I = 0; I <this. rptpaper. Items. Count; I ++)
{
ListBox lB = (ListBox) This. rptpaper. items [I]. findcontrol ("listbox1 ");
ListBox LB2 = (ListBox) This. rptpaper. items [I]. findcontrol ("listbox2 ");
Textbox tbhidanswer = (textbox) rptpaper. items [I]. findcontrol ("tbhidanswer ");
String SLB = LB. selectedvalue;
Tbhidanswer. Text + = SLB + ",";
Dtdb. alertforpage (page, tbhidanswer. Text );
If (Lb. selectedindex! =-1) // The selected
{
Foreach (listitem item in LB. Items)
{
If (item. Selected)
{
Lb2.items. Add (item );
}
}
}
LB. Items. removeat (Lb. selectedindex );
}
}