【发布时间】:2011-02-02 01:21:23
【问题描述】:
您好,我需要稍微修改一下我的代码。我有一个带有单选按钮列表和文本区域的页面。当用户进行单选按钮选择时,会填充文本区域。
此外,当用户进行单选按钮选择时,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 并打开一个新的浏览器,页面不会相应地传递值和数据绑定。页面上没有单选按钮或内容。 一定是我认为的回发逻辑???
什么工作:
- 当我启动网站时,会出现单选按钮并设置索引 0
- 当我选择单选按钮时,正确的数据显示和链接到单选按钮值的网址显示在浏览器中(即http://test.com/test.aspx?selected=2)
- 如果我在同一个浏览器中剪切和粘贴指针 URL,则会呈现正确的数据
什么不起作用(所有处理虚假 PostBack 的东西):
1.当我启动网站时,即使单选按钮设置为 0 索引并且可见,textarea 中也不会出现任何数据。 2. 如果我将指针 url 剪切并粘贴到新的浏览器中,文本区域和单选按钮不显示。
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);
}
}
【问题讨论】:
-
如果循环仅适用于布尔值,则不将任何 int 视为 true
-
感谢您的意见。你能进一步解释你的评论吗?我不明白。
标签: c# asp.net radiobuttonlist