2011-01-21 75 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