方法一:
在CS檔案内使用RowDataBound事件
Code
protected void gvCourseChoosed_RowDataBound( object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string s = e.Row.Cells[ 3 ].Text;
e.Row.Cells[ 3 ].Text = (s == " 0 " ? " 男 " : " 女 " );
}
}
方法二:
直接在aspx檔案内寫
Code
< asp:TemplateField HeaderText = " 性别: " >
< EditItemTemplate >
< asp:DropDownList ID = " DropDownList1 " runat = " server " SelectedValue = ' <%# Bind("TeacherSex") %> ' >
< asp:ListItem Value = " 0 " > 男 </ asp:ListItem >
< asp:ListItem Value = " 1 " > 女 </ asp:ListItem >
</ asp:DropDownList >
</ EditItemTemplate >
< ItemTemplate >
< asp:Label ID = " Label1 " runat = " server " Text = ' <%# (Eval("TeacherSex").ToString()=="0")?"男":"女" %> ' ></ asp:Label >
</ ItemTemplate >
</ asp:TemplateField >
< asp:TemplateField HeaderText = " 出生年月: " >
< EditItemTemplate >
< dxe:ASPxDateEdit ID = " ASPxDateEdit1 " runat = " server " Value = ' <%# Bind("TeacherBirth") %> ' >
</ dxe:ASPxDateEdit >
</ EditItemTemplate >
< ItemTemplate >
< asp:Label ID = " Label2 " runat = " server " Text = ' <%# Bind("TeacherBirth", "{0:d}") %> ' ></ asp:Label >
</ ItemTemplate >
</ asp:TemplateField >