dropdownlist控制checkboxlist和radiobuttonlist的问题

trueeccentry 2005-10-03 11:22:21
一个学生报名系统,根据dropdownlist的选择,跟数据库绑定,出现相应的checkboxlist或radiobuttonlist,然后根据checkboxlist或radiobuttonlist的选择,生成报名科目信息,最后点击一个button,将信息存入数据库.可是我点击button后,数据却进不去.请各位高手指点,到底哪里出现问题.
...全文
98 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tlfangqing 2005-10-04
  • 打赏
  • 举报
回复
错误是什么?
tlfangqing 2005-10-03
  • 打赏
  • 举报
回复
我觉得至少需要检查以下几个方面
1. 存储过程是否正确. 先不要通过页面点击,你在查询分析器中输入个例子看是否能正常工作.
2. 如1步通过,则看你在点击button时, 是否能正确读出关键字段,如学生的学号.

如果以上都正确,那么说明你是什么样的错误.只看代码,看不出什么问题.有点杂. 比如你的代码中那么多的提示完全可以自定义一个函数呀,看起来会更简洁.

skywatcher 2005-10-03
  • 打赏
  • 举报
回复
错误是什么
trueeccentry 2005-10-03
  • 打赏
  • 举报
回复
以上是本人写的代码片段,不知道问题出在什么地方,望各位指点.
trueeccentry 2005-10-03
  • 打赏
  • 举报
回复
private void DropDownList5_SelectedIndexChanged(object sender, System.EventArgs e)
{
Label5.Text="";
CheckBoxList1.Visible=false;
CheckBoxList1.Items.Clear();
RadioButtonList2.Visible=false;
RadioButtonList2.Items.Clear();

if(DropDownList5.SelectedValue=="小学"||DropDownList5.SelectedValue=="初中"||DropDownList5.SelectedValue=="高中")
{
SqlCommand queryCmd1=new SqlCommand("querybranchsubject",myConnection);
queryCmd1.CommandType = CommandType.StoredProcedure;
queryCmd1.Parameters.Add(new SqlParameter("@qsubject",SqlDbType.NChar,20));
queryCmd1.Parameters["@qsubject"].Value = DropDownList5.SelectedItem.Value;
SqlDataReader sdr1;
queryCmd1.Connection.Open();
sdr1=queryCmd1.ExecuteReader();
while(sdr1.Read())
{
CheckBoxList1.Items.Add(new ListItem(sdr1[0].ToString(),sdr1[0].ToString()));
}
CheckBoxList1.Visible=true;
queryCmd1.Connection.Close();
}
else if(DropDownList5.SelectedValue=="大专"||DropDownList5.SelectedValue=="本科")
{
SqlCommand queryCmd1=new SqlCommand("querybranchsubject",myConnection);
queryCmd1.CommandType = CommandType.StoredProcedure;
queryCmd1.Parameters.Add(new SqlParameter("@qsubject",SqlDbType.NChar,20));
queryCmd1.Parameters["@qsubject"].Value = DropDownList5.SelectedItem.Value;
SqlDataReader sdr1;
queryCmd1.Connection.Open();
sdr1=queryCmd1.ExecuteReader();
while(sdr1.Read())
{
RadioButtonList2.Items.Add(new ListItem(sdr1[0].ToString(),sdr1[0].ToString()));
}
RadioButtonList2.Visible=true;
queryCmd1.Connection.Close();
}
}

private void Button1_Click(object sender, System.EventArgs e)
{
if(TextBox1.Text=="")
{
Response.Write("<script language=javascript>alert('请输入姓名!');</script>");
}
else if(RadioButtonList1.SelectedValue=="")
{
Response.Write("<script language=javascript>alert('请选择性别');</script>");
}
else if(TextBox3.Text=="")
{
Response.Write("<script language=javascript>alert('请输入身份证号!');</script>");
}

else if(TextBox5.Text =="")
{
Response.Write("<script language=javascript>alert('请输入住址!');</script>");
}
else if(TextBox6.Text =="")
{
Response.Write("<script language=javascript>alert('请输入电话号码!');</script>");
}
else if(TextBox7.Text =="")
{
Response.Write("<script language=javascript>alert('请输入E-Mail!');</script>");
}
else if(DropDownList5.SelectedItem.Value =="")
{
Response.Write("<script language=javascript>alert('请选择报名科目!');</script>");
}
else if(TextBox9.Text =="")
{
Response.Write("<script language=javascript>alert('请输入籍贯!');</script>");
}
else if(TextBox8.Text =="")
{
Response.Write("<script language=javascript>alert('请输入金额!');</script>");
}
else if(TextBox3.Text.Length!=15 & TextBox3.Text.Length!=18 )
{
Response.Write("<script language=javascript>alert('请输入有效身份证号码!');</script>");
}
else if(DropDownList5.SelectedValue=="小学"||DropDownList5.SelectedValue=="初中"||DropDownList5.SelectedValue=="高中")
{
if(CheckBoxList1.SelectedValue=="")
{
Response.Write("<script language=javascript>alert('请选择分类科目!');</script>");
}
}
else if(DropDownList5.SelectedValue=="大专"||DropDownList5.SelectedValue=="本科")
{
if(RadioButtonList2.SelectedValue=="")
{
Response.Write("<script language=javascript>alert('请选择分类科目!');</script>");
}
}

else
{
String birthdate=null;

if(TextBox3.Text.Length==15)
{
birthdate="19"+TextBox3.Text.Substring(6,2)+"年"+TextBox3.Text.Substring(8,2)+"月"+TextBox3.Text.Substring(10,2)+"日";
}
else if(TextBox3.Text.Length==18)
{
birthdate=TextBox3.Text.Substring(6,4)+"年"+TextBox3.Text.Substring(10,2)+"月"+TextBox3.Text.Substring(12,2)+"日";
}

subject=DropDownList5.SelectedValue.Trim();

myConnection=new SqlConnection("server=.;database=sjinfo;user id=sa;password=");

SqlCommand insertCmd=new SqlCommand("insertreginfo1",myConnection);
insertCmd.CommandType = CommandType.StoredProcedure;

insertCmd.Parameters.Add(new SqlParameter("@iname",SqlDbType.NChar,10));
insertCmd.Parameters["@iname"].Value = TextBox1.Text;

insertCmd.Parameters.Add(new SqlParameter("@igender",SqlDbType.NChar,5));
insertCmd.Parameters["@igender"].Value = RadioButtonList1.SelectedValue;

insertCmd.Parameters.Add(new SqlParameter("@iIdentityNumber",SqlDbType.NChar,20));
insertCmd.Parameters["@iIdentityNumber"].Value = TextBox3.Text;

insertCmd.Parameters.Add(new SqlParameter("@idateofbirth",SqlDbType.NChar,20));
insertCmd.Parameters["@idateofbirth"].Value = birthdate;

insertCmd.Parameters.Add(new SqlParameter("@iplace",SqlDbType.NChar,50));
insertCmd.Parameters["@iplace"].Value =TextBox2.Text;

insertCmd.Parameters.Add(new SqlParameter("@iaddress",SqlDbType.NChar,50));
insertCmd.Parameters["@iaddress"].Value = TextBox5.Text;

insertCmd.Parameters.Add(new SqlParameter("@itel",SqlDbType.NChar,20));
insertCmd.Parameters["@itel"].Value = TextBox6.Text;

insertCmd.Parameters.Add(new SqlParameter("@iemail",SqlDbType.NChar,20));
insertCmd.Parameters["@iemail"].Value = TextBox7.Text;

insertCmd.Parameters.Add(new SqlParameter("@isubject",SqlDbType.NChar,50));
insertCmd.Parameters["@isubject"].Value =DropDownList5.SelectedValue;

insertCmd.Parameters.Add(new SqlParameter("@iprice",SqlDbType.NChar,10));
insertCmd.Parameters["@iprice"].Value = TextBox4.Text;

insertCmd.Parameters.Add(new SqlParameter("@iextraprice",SqlDbType.NChar,10));
insertCmd.Parameters["@iextraprice"].Value = TextBox8.Text;

insertCmd.Parameters.Add(new SqlParameter("@inativeplace",SqlDbType.NChar,50));
insertCmd.Parameters["@inativeplace"].Value = TextBox9.Text;

insertCmd.Parameters.Add(new SqlParameter("@istudentid",SqlDbType.NChar,20));
insertCmd.Parameters["@istudentid"].Value =studentID;

insertCmd.Parameters.Add(new SqlParameter("@idateofregist",SqlDbType.NChar,20));
insertCmd.Parameters["@idateofregist"].Value = Label13.Text;

insertCmd.Parameters.Add(new SqlParameter("@iperson",SqlDbType.NChar,20));
insertCmd.Parameters["@iperson"].Value = person;

try
{
insertCmd.Connection.Open();
insertCmd.ExecuteNonQuery();
myConnection.Close();
Response.Redirect("confirm.aspx?name="+TextBox1.Text+"&sid="+studentID+"&subject="+subject+"&extraprice="+TextBox8.Text+"&price="+TextBox4.Text+"&branch="+branch+"&gender="+RadioButtonList1.SelectedValue+"&idennumber="+TextBox3.Text+"&dateofbirth="+birthdate+"&person="+person+"&nativeplace="+TextBox9.Text);
}
catch(Exception ee)
{
}
myConnection.Close();

}
}
trueeccentry 2005-10-03
  • 打赏
  • 举报
回复
<%@ Page language="c#" Codebehind="regist1.aspx.cs" AutoEventWireup="false" Inherits="SJManage.regist1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>regist1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script runat="server">

void Check_Clicked(Object sender, EventArgs e)
{
Label5.Text = "";

// Iterate through the Items collection of the CheckBoxList
// control and display the selected items.
for (int i=0; i<CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
Label5.Text += CheckBoxList1.Items[i].Text;
}
}
}

void Check_Clicked1(Object sender, EventArgs e)
{
Label5.Text=RadioButtonList2.SelectedValue;
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:textbox id="TextBox9" style="Z-INDEX: 124; LEFT: 267px; POSITION: absolute; TOP: 152px"
runat="server"></asp:textbox><asp:label id="Label5" style="Z-INDEX: 130; LEFT: 501px; POSITION: absolute; TOP: 382px" runat="server"></asp:label><asp:linkbutton id="LinkButton1" style="Z-INDEX: 129; LEFT: 424px; POSITION: absolute; TOP: 520px"
runat="server">返回报名系统主页</asp:linkbutton><asp:radiobuttonlist id="RadioButtonList2" style="Z-INDEX: 128; LEFT: 411px; POSITION: absolute; TOP: 336px"
runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="Check_Clicked1" Visible="False"></asp:radiobuttonlist><asp:checkboxlist id="CheckBoxList1" style="Z-INDEX: 127; LEFT: 387px; POSITION: absolute; TOP: 336px"
runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="Check_Clicked" Visible="False"></asp:checkboxlist><asp:textbox id="TextBox4" style="Z-INDEX: 126; LEFT: 267px; POSITION: absolute; TOP: 376px"
runat="server"></asp:textbox><asp:label id="Label1" style="Z-INDEX: 125; LEFT: 224px; POSITION: absolute; TOP: 24px" runat="server"
Font-Size="Large" ForeColor="Red" Font-Bold="True">欢迎进入学员报名</asp:label><asp:label id="Label15" style="Z-INDEX: 123; LEFT: 144px; POSITION: absolute; TOP: 154px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="96px">籍贯:</asp:label><asp:textbox id="TextBox8" style="Z-INDEX: 122; LEFT: 267px; POSITION: absolute; TOP: 416px"
runat="server"></asp:textbox><asp:label id="Label14" style="Z-INDEX: 121; LEFT: 127px; POSITION: absolute; TOP: 413px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="113px">代办费:</asp:label><asp:textbox id="TextBox2" style="Z-INDEX: 120; LEFT: 267px; POSITION: absolute; TOP: 192px"
runat="server"></asp:textbox><asp:radiobuttonlist id="RadioButtonList1" style="Z-INDEX: 119; LEFT: 529px; POSITION: absolute; TOP: 80px"
runat="server" RepeatDirection="Horizontal" Width="104px" Height="8px">
<asp:ListItem Value="男">男</asp:ListItem>
<asp:ListItem Value="女">女</asp:ListItem>
</asp:radiobuttonlist><asp:label id="Label13" style="Z-INDEX: 118; LEFT: 275px; POSITION: absolute; TOP: 456px" runat="server"></asp:label><asp:label id="Label12" style="Z-INDEX: 117; LEFT: 109px; POSITION: absolute; TOP: 456px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="131px" Height="18">注册日期:</asp:label><asp:button id="Button1" style="Z-INDEX: 116; LEFT: 296px; POSITION: absolute; TOP: 512px" runat="server"
Font-Size="Medium" Font-Bold="True" Text="提交"></asp:button><asp:textbox id="TextBox7" style="Z-INDEX: 115; LEFT: 267px; POSITION: absolute; TOP: 296px"
runat="server" Height="22px"></asp:textbox><asp:label id="Label11" style="Z-INDEX: 114; LEFT: 123px; POSITION: absolute; TOP: 302px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="117px" Height="18">E-Mail:</asp:label><asp:dropdownlist id="DropDownList5" style="Z-INDEX: 113; LEFT: 267px; POSITION: absolute; TOP: 336px"
runat="server" AutoPostBack="True" Width="96px" Height="22">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="日语">日语</asp:ListItem>
<asp:ListItem Value="韩语">韩语</asp:ListItem>
<asp:ListItem Value="英语">英语</asp:ListItem>
<asp:ListItem Value="成人高复">成人高复</asp:ListItem>
<asp:ListItem Value="大专">大专</asp:ListItem>
<asp:ListItem Value="本科">本科</asp:ListItem>
<asp:ListItem Value="报关员">报关员</asp:ListItem>
<asp:ListItem Value="建筑">建筑</asp:ListItem>
<asp:ListItem Value="小学">小学</asp:ListItem>
<asp:ListItem Value="初中">初中</asp:ListItem>
<asp:ListItem Value="高中">高中</asp:ListItem>
<asp:ListItem Value="国美专修">国美专修</asp:ListItem>
</asp:dropdownlist><asp:textbox id="TextBox6" style="Z-INDEX: 112; LEFT: 267px; POSITION: absolute; TOP: 256px"
runat="server" Width="156" Height="22px"></asp:textbox><asp:textbox id="TextBox5" style="Z-INDEX: 111; LEFT: 267px; POSITION: absolute; TOP: 224px"
runat="server" Width="272px" Height="22px"></asp:textbox><asp:textbox id="TextBox3" style="Z-INDEX: 110; LEFT: 267px; POSITION: absolute; TOP: 120px"
runat="server" Width="156" Height="22px"></asp:textbox><asp:textbox id="TextBox1" style="Z-INDEX: 109; LEFT: 267px; POSITION: absolute; TOP: 80px" runat="server"
Width="88px" Height="22px"></asp:textbox><asp:label id="Label10" style="Z-INDEX: 108; LEFT: 139px; POSITION: absolute; TOP: 376px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="101px" Height="16px">学费:</asp:label><asp:label id="Label9" style="Z-INDEX: 107; LEFT: 107px; POSITION: absolute; TOP: 339px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="133px" Height="18px">报名科目:</asp:label><asp:label id="Label8" style="Z-INDEX: 106; LEFT: 109px; POSITION: absolute; TOP: 265px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="131px" Height="18px">联系电话:</asp:label><asp:label id="Label7" style="Z-INDEX: 105; LEFT: 109px; POSITION: absolute; TOP: 228px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="131px" Height="18">家庭住址:</asp:label><asp:label id="Label6" style="Z-INDEX: 104; LEFT: 107px; POSITION: absolute; TOP: 191px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="133px" Height="18">报名地点:</asp:label><asp:label id="Label4" style="Z-INDEX: 103; LEFT: 109px; POSITION: absolute; TOP: 117px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="131px" Height="18px">身份证号:</asp:label><asp:label id="Label3" style="Z-INDEX: 102; LEFT: 465px; POSITION: absolute; TOP: 80px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="56px">性别:</asp:label><asp:label id="Label2" style="Z-INDEX: 101; LEFT: 139px; POSITION: absolute; TOP: 80px" runat="server"
ForeColor="#0000C0" Font-Bold="True" Width="101px" Height="18">姓名:</asp:label></FONT></form>
</body>
</HTML>
trueeccentry 2005-10-03
  • 打赏
  • 举报
回复
存储过程正确,我试过。点击BUTTON,也能读得出字段

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧