[英]linking to a radiobutton value, data is not binding, asp.net c#
嗨,我需要修改我的代码一点。 我有一个带有单选按钮列表和文本区域的页面。 用户选择单选按钮时,将填充文本区域。
同样,当用户选择单选按钮时,URL将在URL中保留一个扩展名以显示他们具有选择的选择索引号。 (即?selected = 0)
http://test.com/frm_Articles.aspx?selected=0 http://test.com/frm_Articles.aspx?selected=1 http://test.com/frm_Articles.aspx?selected=2
这样,他们可以复制该网址,并在其他网站中将其作为链接引用。 或将其放置在他们的收藏夹中。
问题是,如果您获取URL并打开新的浏览器,则该页面不会传递该值,并且不会相应地进行数据绑定。 页面上没有单选按钮或内容。 一定是我认为的回发逻辑???
工作原理:
什么不起作用(处理错误的PostBack的所有内容):
1.当我启动网站时,即使单选按钮设置为0索引并且可见,textarea内也没有数据。 2.如果我将指针网址剪切并粘贴到新的浏览器中,则不会显示文本区域和单选按钮。
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
int selected;
if (Request.QueryString["selected"] != null)
{
if (int.TryParse(Request.QueryString["selected"], out selected))
{
RadioButtonList1.SelectedIndex = selected;
RadioButtonList1.DataBind();
}
}
else
{
int firstart = 0;
RadioButtonList1.SelectedIndex = firstart;
RadioButtonList1.DataBind();
}
}
}
protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
//
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
try{
e.Command.Parameters["@URL_FK"].Value = Session["URL_PK"];
}
catch (Exception ex)
{
}
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
string strRedirect;
strRedirect = "test.aspx?selected=" + RadioButtonList1.SelectedIndex;
Response.Redirect(strRedirect);
}
}
在您的代码中此行之前的Page_Load
事件中
RadioButtonList1.SelectedIndex = selected;
您应该绑定RadioButtonList1。 绑定RadioButtonList之后,可以设置SelectedIndex
。
我的SqlDataSource1_Selecting方法就是问题所在。 我使用了另一种方法,我的代码工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.