2011-01-21 73 views
0

嗨,我需要修改我的代码一点点。我有一个单选按钮列表和一个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并打开一个新的浏览器,页面不会相应地传递值和数据绑定。没有单选按钮或内容出现在页面上。 必须是我认为的回发逻辑?

什么工作:

  1. 当我启动该网站的单选按钮出现,指数设定为0
  2. 当我选择单选按钮正确的数据显示和链接到单选按钮值的网址在浏览器中显示(即http://test.com/test.aspx?selected=2)相同的浏览器,然后正确的数据呈现

什么行不通内

  • 如果我剪切和粘贴指针的URL(一切牛逼帽子处理一个错误的回发):

    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); 
    
        } 
    
    
    } 
    
  • +0

    如果循环仅适用于布尔值,则不考虑任何int为真 – Learner 2011-01-21 09:14:05

    回答

    0

    我的SqlDataSource1_Selecting方法是问题。我用另一种方法,我的代码工作。

    1

    在你的代码在Page_Load事件此行

    RadioButtonList1.SelectedIndex = selected;

    你应该绑定RadioButtonList1之前。绑定RadioButtonList后,您可以设置SelectedIndex