动态显示男女性别的两种方法

方法一:

在CS文件内使用RowDataBound事件


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文件内写


< 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 >

你可能感兴趣的:(动态显示男女性别的两种方法)