请问高手:为什么我的这个RadioButtonList控件的事件不起作用?
我估计是我在.CS中事件的代码有问题。我现在想实现的功能是.当我在点击RadioButtonList的某个选项项时,然后我在页面中的一个TextBox控件txtIntroduce控件的值(此值读取的是SAT_Explain字段的值)也相应的变化。请高手教教我.致谢!
.aspx中的控件代码:
<asp:RadioButtonList ID="TypeList" runat="server" RepeatDirection="Horizontal" Width="95%"
RepeatColumns="4" OnSelectedIndexChanged="TypeList_SelectedIndexChanged">
.cs中的事件代码:
protected void TypeList_SelectedIndexChanged(object sender, EventArgs e)
{
//bind
SqlDataAdapter myadp = new SqlDataAdapter("select sat_id,sat_name,SAT_Explain from tc_serviceapptype where sat_parentid=2", MyCls.SqlConn);
DataSet myds = new DataSet();
myadp.Fill(myds, "sertype"); TypeList.DataSource = myds;
TypeList.DataValueField = "sat_id";
TypeList.DataTextField = "sat_name";
TypeList.DataBind();
if (this.TypeList.SelectedValue.Equals("1"))
{
txtIntroduce.Text = myds.Tables["sertype"].Rows[0]["SAT_Expain"].ToString();
}
我估计是我在.CS中事件的代码有问题。我现在想实现的功能是.当我在点击RadioButtonList的某个选项项时,然后我在页面中的一个TextBox控件txtIntroduce控件的值(此值读取的是SAT_Explain字段的值)也相应的变化。请高手教教我.致谢!
.aspx中的控件代码:
<asp:RadioButtonList ID="TypeList" runat="server" RepeatDirection="Horizontal" Width="95%"
RepeatColumns="4" OnSelectedIndexChanged="TypeList_SelectedIndexChanged">
.cs中的事件代码:
protected void TypeList_SelectedIndexChanged(object sender, EventArgs e)
{
//bind
SqlDataAdapter myadp = new SqlDataAdapter("select sat_id,sat_name,SAT_Explain from tc_serviceapptype where sat_parentid=2", MyCls.SqlConn);
DataSet myds = new DataSet();
myadp.Fill(myds, "sertype"); TypeList.DataSource = myds;
TypeList.DataValueField = "sat_id";
TypeList.DataTextField = "sat_name";
TypeList.DataBind();
if (this.TypeList.SelectedValue.Equals("1"))
{
txtIntroduce.Text = myds.Tables["sertype"].Rows[0]["SAT_Expain"].ToString();
}
解决方案 »
- VS2008项目文件中编辑前台源代码时就“假死机”,高手出来啊!
- 请一个求最大数的sql
- vs2008 visual studio Tools 没有命令提示符2008
- 救助:VS2005中可能是配置错误??
- 不明白,求教:如何执行这种方法?难道是解决方案有问题?
- ASP.NET前台调用后台函数并传参数问题.高手帮忙
- 菜鸟问题:怎样做弹出页面啊??希望哪位大虾给出详细代码!!!
- 使用.Net自带的邮件类发送邮件报异常
- 万能的CSDN啊~~求大神..IIS服务器无响应 从IIS 8到VS2012 自带的Development Server..
- 在treeview中 如何设置父子节点
- windows2003下.net runtime错误,请高手指点
- |zyciis| 如何最好的遍历网页中的所有Button控件 用Fearch没有办法啊
建议:将TypeList的绑定移出来。
{
//bind
SqlDataAdapter myadp = new SqlDataAdapter("select sat_id,sat_name,SAT_Explain from tc_serviceapptype where sat_parentid=2", MyCls.SqlConn);
DataSet myds = new DataSet();
myadp.Fill(myds, "sertype"); TypeList.DataSource = myds;
TypeList.DataValueField = "sat_id";
TypeList.DataTextField = "sat_name";
TypeList.DataBind();
foreach(ListItme li in This.TypeList.Items)
{
if (li.selected&&this.TypeList.SelectedValue.Equals("1"))
{
txtIntroduce.Text += myds.Tables["sertype"].Rows[0]["SAT_Expain"].ToString()+"<br/>";
}
}
protected void TypeList_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataAdapter myadp = new SqlDataAdapter("select sat_id,sat_name,SAT_Explain from tc_serviceapptype where sat_parentid=2", MyCls.SqlConn);
DataSet myds = new DataSet();
myadp.Fill(myds, "sertype"); TypeList.DataSource = myds;
TypeList.DataValueField = "sat_id";
TypeList.DataTextField = "sat_name";
TypeList.DataBind(); foreach (ListItem li in this.TypeList.Items)
{
if (this.TypeList.SelectedValue.Equals("1"))
{
txtIntroduce.Text = myds.Tables["sertype"].Rows[0]["SAT_Explain"].ToString();
}
}
}在我选择RadioButtonList控件的其它项时,TextBox控件(控件名是txtIntroduce,与RadioButtonList在同一个页面)的内容总是显示为第一项的内容(此内容是字段SAT_Explain记录的).我现在需要达到的效果是:用户选择RadioButtonList控件的其它项时,TextBox控件中的内容也要跟着读取字段SAT_Explain中的相对应的内容. 请高手帮我改改代码,在下学习一下.
现在主要两个问题,解决就好了:
1、if (this.TypeList.SelectedValue.Equals("1"))这个条件判断的结果老是为false,并且我这写我想是一定有问题的,Equals("1")就是我直截给的一个值,其实这个Equals("")引号中的值是应该变化的。
2、我现在需要达到的效果是:用户选择RadioButtonList控件的其它项时,TextBox控件中的内容也要跟着读取字段SAT_Explain中的相对应的内容. 也就是用户在点击选择RadioButtonList各个项时,TextBox中要显示不同的内容。
请高手帮我改改代码,或给我一个关于RadioButtonList控件事件的代码我学习一下。
我加分了。
我把这个问题的页面代码发到一个链接下面,请高手下载解决:www.tontel.com.cn/download/RadioButtonList.rar
致谢!
我的:E_mail、QQ、MSN都是[email protected]
protected void TypeList_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet myds = ViewState["myds"] as DataSet;
int SelectedIndex = TypeList.SelectedIndex;
foreach (DataRow row in myds.Tables[0].Rows)
{
if (TypeList.Items[SelectedIndex].Value.Equals(Convert.ToString(row["sat_id"])))
{
txtIntroduce.Text = Convert.ToString(row["SAT_Explain"]);
}
}不过, 这个情况也要在Page_Load里面添加判断代码.
if (TypeList.Items.Count > 0)
{
if (TypeList.Items.Count >= SelectedIndex)
{
TypeList.SelectedIndex = SelectedIndex;
}
else
{
TypeList.SelectedIndex = 0;
}
}谢谢各位参与给在下帮忙.