在鏈接按鈕中,將下拉列表中的ID從會話ID保存到會話ID併發送文本以獲取選定內容,並且在網格上單擊選擇鏈接時在表單中自動填充表單做工精細..但試圖挽救button_save給予不設置到對象的實例錯誤對象引用...猜它與追趕dropdownvalue問題的時候.. plz幫助未將對象引用設置爲對象的實例..錯誤
public partial class Admin_AddSubject : System.Web.UI.Page
{
Add_Subject cm = new Add_Subject();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sms"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
classfill();
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton b = (LinkButton)sender;
GridViewRow row = (GridViewRow)b.NamingContainer;
if (row != null)
{
int rowIndex = row.RowIndex;
string pid = GridView1.DataKeys[rowIndex].Values["pid"].ToString();
string subject = GridView1.DataKeys[rowIndex].Values["subject"].ToString();
string id = GridView1.DataKeys[rowIndex].Values["id"].ToString();
Session["pid"] = pid.ToString();
// saving id from dropdownlist to session
Session["id"] = ddl_class.SelectedItem.Text;
TextBoxSubject.Text = subject.ToString();
//sending dropdownlist text to get selected
ddl_class.Text = id.ToString();
}
}
protected void ButtonSave_Click(object sender, EventArgs e)
{
// error: Object reference not set to an instance of an object.
cm.ButtonSave_Click(int.Parse(Session["id"].ToString()),TextBoxSubject.Text);
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "alert", "alert('Your data successfully Saved..');", true);
ddl();
clear();
}
你在哪裏宣佈釐米? –
聽起來像這個問題是一個對象引用沒有設置爲一個對象的實例... – Phill
這一行中的一件事是null cm.ButtonSave_Click(int.Parse(Session [「id」]。ToString() ),TextBoxSubject.Text);'可能cm或Session [「id」]調試它找出哪些和爲什麼。 –