嗨,我需要修改我的代码一点点。我有一个单选按钮列表和一个textarea页面。当用户进行单选按钮选择时,textarea被填充。链接到单选按钮值,数据没有绑定,asp.net c#
此外,当用户进行单选按钮选择时,url将在url中保留一个扩展名,以显示他们有选择的选择索引号。 (即?选定= 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和作为一个链接在其他网站引用它。或将其放入他们的收藏夹中。
问题是,如果你抓住url并打开一个新的浏览器,页面不会相应地传递值和数据绑定。没有单选按钮或内容出现在页面上。 必须是我认为的回发逻辑?
什么工作:
- 当我启动该网站的单选按钮出现,指数设定为0
- 当我选择单选按钮正确的数据显示和链接到单选按钮值的网址在浏览器中显示(即http://test.com/test.aspx?selected=2)相同的浏览器,然后正确的数据呈现
什么行不通内
1.when我启动网站没有数据在textarea apprears内,即使单选按钮设置为0索引,并且可见。 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为真 – Learner 2011-01-21 09:14:05