GridView中有一个模板列,如下:

                   
                       
                           
                           
                           
                           

                       

                   

数据库中男女使用bit类型(即:True、False)存储的

我想用Eval或DataBind实现:

如果数据库中为True则第一个ListItem选址中 即

如果数据库z中为False则第二个ListItem选中

 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        RadioButtonList r = (RadioButtonList)e.Row.FindControl("rbl_Xb");
        System.Data.DataRowView data = (System.Data.DataRowView)e.Row.DataItem;
        bool qx = Convert.ToBoolean(data["qx1"]); //qx1是个bit字段
        if (qx)
        {
            r.Items.FindByText("男").Selected = true;
        }
        else
        {
            r.Items.FindByText("女").Selected = true;
        }
    }
}