日期:2014-05-17  浏览次数:20431 次

问个菜鸟的问题绑定到数据库?
问个菜鸟的问题。
一个留言本姓名是这样绑定到数据库的 <tr>
          <td width="300" height="40" align="right">姓名:</td>
          <td align="left" width="300"><asp:TextBox ID="name1TextBox" runat="server" Text='<%# Bind("name1") %>' Width="120px"></asp:TextBox></td>
        </tr>
性别有男和女两个选项。
我这样绑定到数据库结果显示错误,麻烦各位高手给回答一样,错在哪里,如何修改才能把性别的值绑定到数据库?
  <tr>
          <td height="40" align="right">性别:</td>
          <td align="left"width="300" >
          <asp:RadioButtonList id="sexTextBox" runat="server">
<asp:ListItem value="男"  Text='<%# Bind("sex") %>' selected="true" Width="60px"/>
<asp:ListItem value="女"  Text='<%# Bind("sex") %>' Width="60px" />

</asp:RadioButtonList>
          
          
</td>
        </tr>

------解决方案--------------------
default.aspx页面

<div>
   <asp:RadioButtonList ID="RBL1" runat="server" Height="30px" Width="98px">
        <asp:ListItem Text="A1 0分" Value='0'></asp:ListItem>
        <asp:ListItem Text="A1 5分" Value='5'></asp:ListItem>
   </asp:RadioButtonList>
</div>

一、绑定数据为数组

参考:
ArrayList al=new ArrayList();
   al.Add("sdfd");
   al.Add("dfgd");
   al.Add("rete");
   al.Add("fghfgh");
   al.Add("fghfghrete");
        
   RBL1.DataSource = al;
   RBL1.DataBind();

------解决方案--------------------
目测似乎sex字段用的字符串类型
<asp:RadioButtonList id="sexTextBox" runat="server" SelectedValue='<%# Bind("sex") %>'>
<asp:ListItem value="男"  Text="男" selected="true" Width="60px"/>
<asp:ListItem value="女"  Text="女" Width="60px" />

如果用的bit型,将value改成True和False
------解决方案--------------------
引用:
问个菜鸟的问题。
一个留言本姓名是这样绑定到数据库的 <tr>
          <td width="300" height="40" align="right">姓名:</td>
          <td align="left" width="300"><asp:TextBox ID="name1TextBox" runat="server" Text='<%#&nb