在链接按钮中,将下拉列表中的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”]调试它找出哪些和为什么。 –