1. Change the plain text content. If the sex field in the student information table in the database uses 0 and 1 to represent men and women, but we want to bind the repeat control to show that the gender is male or female instead of 0 or 1.
Repeater or DataList Control
1. Change the plain text content. If the sex field in the student information table in the database tutorial uses 0 and 1 to indicate male and female, but we want to bind the repeat control to show male or female, instead of 0 or 1.
Method 1: Of course, we can judge and convert in SQL statements
Select (case sex when 0 then 'male' else 'female' end) AS sex from studentInfo
Method 2: Use the repeat control ItemDataBound () event
<Asp Tutorial: Repearter ID = "Repeater1" runat = "server" onitemdatabound = "repeaterincluitemdatabound">
<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 repeaterincluitemdatabound (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 ";
}
For example, if you want to display the male row as a style, the female row generated is a style (if it is a repeater control)
(Label) e. Item. FindControl ("lblSex"). CssClass = "style_male ";
Of course, you can also set a prompt (Label) e. Item. FindControl ("lblSex"). ToolTip = "I Am a man"
If it is a DataList control, you can also set the style of that row directly.
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"; break;
Case 1: e. Item. CssClass = "red"; break;
Case 2: e. Item. CssClass = "purple"; break;
Case 3: e. Item. CssClass = "yellow"; break;
Case 4: e. Item. CssClass = "blue"; break;
Case 5: e. Item. CssClass = "green"; break;
}
}