One: Repeater or DataList controls
1. Change plain text content if the sex field in the Student Information table in the database is represented by 0 and a man but we want to repeat the control after the sex shows the male or female instead of showing 0 or 1
Method One: Of course we can judge and convert in SQL statements
Select (Case sex when 0 then ' men ' else ') as sex from Studentinfo
Method Two: is to use the Repeat Control ItemDataBound () event
Front desk
Copy Code code as follows:
<asp:repearter id= "Repeater1" runat= "Server" onitemdatabound= "Repeater1_itemdatabound" >
<ItemTemplate>
<tr>
<td>
<input type= "checkbox" >
</td>
<TD style= "Text-align:center" >
<% #Eval ("StudentID")%>
</td>
<TD style= "Text-align:center" >
<asp:label id= "Lblsex" runat= "Server" text= "" >
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
protected void Repeater1_itemdatabound (object sender, RepeaterItemEventArgs e)
{
DataRowView DRV = (DataRowView) e.Item.DataItem;
if (drv["sex"]. ToString () = = "0")
{
((Label) E.item.findcontrol ("Lblsex")). Text = "male";
}
Else ((Label) E.item.findcontrol ("Lblsex")). Text = "female";
}
2. Display different styles (CSS) based on the line conditions to be generated
For example, to show the behavior of a man a style, the generation of women's line is a style that is (if the Repeater control)
((Label) E.item.findcontrol ("Lblsex")). Cssclass= "Style_male";
Of course, you can also set the prompt ((Label) E.item.findcontrol ("Lblsex"). Tooltip= "I'm a man."
If it's a DataList control, you can also set the style for that line directly.
Copy Code code as follows:
private void Assets_itendatabound (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
DataRowView drv= (DataRowView) e.Item.DataItem;
String m= (String) drv["ID"];
int i=_usermenubll.assetscss (m);
Switch (i)
{
Case 0:e.item.cssclass= "Nomal";
Case 1:e.item.cssclass= "Red";
Case 2:e.item.cssclass= "Purple";
Case 3:e.item.cssclass= "Yellow";
Case 4:e.item.cssclass= "Blue";
Case 5:e.item.cssclass= "Green";
}
}
If it is a GridView control, use the GridView1_RowDataBound
Set E. Row.cssclass Of course can also use E. Row.findcontrol method