我做的学生基本信息管理系统能从数据库中获取到文本的信息,但是RadioButtonList,DropDownList,CheckBoxList这三个控件却获取不到。
DropDownList1是图中要选择学号的下拉列表的id号。
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem Value="女">女</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>计算机科学与技术</asp:ListItem>
<asp:ListItem>软件工程</asp:ListItem>
<asp:ListItem>电子商务</asp:ListItem>
</asp:DropDownList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem>是</asp:ListItem>
<asp:ListItem>否</asp:ListItem>
</asp:CheckBoxList>
后台代码
protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "Server=(local);Database=student;User ID=sa;Password=;Integrated Security=True;";
SqlConnection conn=new SqlConnection(strConn);
try
{
conn.Open();
string searchstu="select * from stuData where sno='"+Convert.ToString(DropDownList1.SelectedItem.Value)+"'";
SqlCommand cmd=new SqlCommand(searchstu,conn);
SqlDataReader sdr=cmd.ExecuteReader();
while(sdr.Read())
{
Text_sno.Text=sdr["sno"].ToString();
Text_name.Text=sdr["name"].ToString();
RadioButtonList1.SelectedValue=sdr["sex"].ToString();
Text_birth.Text=sdr["birthDate"].ToString();
DropDownList2.SelectedValue = sdr["major"].ToString();
CheckBoxList1.SelectedValue=sdr["loan"].ToString();
Text_id.Text=sdr["idCard"].ToString();
Text_np.Text=sdr["nativePlace"].ToString();
Text_addr.Text=sdr["address"].ToString();
}
sdr.Close();
conn.Close();
Response.Write("数据库表查找成功");
}
catch(SqlException sqle){
Response.Write(sqle.Message);
}
}
附的图是运行的结果,其中有值的是从数据库获取的,
主要是这三句话有问题RadioButtonList1.SelectedValue=sdr["sex"].ToString();
DropDownList2.SelectedValue = sdr["major"].ToString();
CheckBoxList1.SelectedValue=sdr["loan"].ToString();
哪位骨灰级人物能帮帮我啊。感激不尽。。。