2016-12-26 15 views
-4

我用了2個控件編輯gridview的inside.It正確的格式顯示錯誤「輸入字符串是不正確的格式」輸入字符串的不爲單選按鈕

protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
      { 
       fill_grd(); 
       fill_gender(); 
      }  
     } 

     public void fill_gender() 
     { 
      con.Open(); 

      SqlCommand cmd = new SqlCommand("usp_Gender_get", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      SqlDataAdapter da = new SqlDataAdapter(cmd); 
      DataSet ds = new DataSet(); 
      da.Fill(ds); 
      if (ds.Tables[0].Rows.Count > 0) 
      { 
       radiolist.DataValueField = "Gid"; 
       radiolist.DataTextField = "Gname"; 
       radiolist.DataSource = ds; 
       radiolist.DataBind(); 
      } 

      con.Close(); 
     } 

     public void fill_grd() 
     { 
      con.Open(); 

      SqlCommand cmd = new SqlCommand("usp_Login_get", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      SqlDataAdapter da = new SqlDataAdapter(cmd); 
      DataSet ds = new DataSet(); 
      da.Fill(ds); 
      if (ds.Tables[0].Rows.Count > 0) 
      { 
       grd.DataSource = ds; 
       grd.DataBind(); 
      } 
      else 
      { 

       grd.DataSource = null; 
       grd.DataBind(); 
      } 
      con.Close(); 
     } 

     protected void grd_RowEditing(object sender, GridViewEditEventArgs e) 
     { 
      grd.EditIndex = e.NewEditIndex; 
      fill_grd(); 
     } 

     protected void grd_RowDeleting(object sender, GridViewDeleteEventArgs e) 
     { 
      int id = int.Parse(grd.DataKeys[e.RowIndex].Value.ToString()); 
      con.Open(); 
      SqlCommand cmd = new SqlCommand("usp_Login_delete", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      cmd.Parameters.AddWithValue("@Lid", id); 
      cmd.ExecuteNonQuery(); 
      con.Close(); 
      fill_grd(); 
     } 

     protected void grd_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 

      TextBox TB1 = (TextBox)grd.Rows[e.RowIndex].FindControl("edittxtname"); 
      RadioButtonList RBL1 = (RadioButtonList)grd.Rows[e.RowIndex].FindControl("editradiolist"); 

      int id = int.Parse(grd.DataKeys[e.RowIndex].Value.ToString()); 
      con.Open(); 
      SqlCommand cmd = new SqlCommand("usp_Login_update", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      cmd.Parameters.AddWithValue("@Lid", id); 
      cmd.Parameters.AddWithValue("@Name", TB1.Text); 
      cmd.Parameters.AddWithValue("@Gender", RBL1.SelectedValue); 
      cmd.ExecuteNonQuery(); 
      con.Close(); 
      grd.EditIndex = -1; 
      fill_grd(); 
     } 

     protected void grd_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 
     { 
      grd.EditIndex = -1; 
      fill_grd(); 
     } 

     protected void savebtn_Click(object sender, EventArgs e) 
     { 
      con.Open(); 

      SqlCommand cmd = new SqlCommand("usp_Login_insert", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      cmd.Parameters.AddWithValue("@Name", txtname.Text); 
      cmd.Parameters.AddWithValue("@Gender", int.Parse(radiolist.SelectedValue)); 
      cmd.ExecuteNonQuery(); 
      con.Close(); 
      fill_grd(); 
     } 
    } 
} 
+6

該代碼與單選按鈕無關;請發佈產生該錯誤的實際代碼。 –

回答

0

不知道在您的錯誤發生並且你粘貼的代碼與你的問題確實無關,但我會盡力回答。

您需要檢查單選按鈕的數據類型,它可能不是布爾或int。看來你是從你從數據庫中得到的結果中設置數據類型,我猜你需要通過檢查存儲過程usp_Login_get和你爲radiobutton列設置的數據類型來改變數據類型。