0

HI Friends,

On Button click(postback), my dropdownlist of gridview is getting blank, so i m getting error of "Object Reference...." on the line "ddl.selecteditem.value"

Also, dropdownlist's selectedindexchanged event is fired on Button Click(Page Postback), which is making the dropdownlist to go blank. AutoPostBack of dropdownlist is set as False, still the event is fired

Pls help

Regards

Suresh G

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by jugosoft
0

When form is submitted, SelectedIndex property is lost, you must save it with query string, session or something, and then you can use it without error.

Response.Redirect("page.aspx?index=" + dropDownList1.SelectedIndex);

or

// Saving the selected index value
Session["index"] = dropDownList1.SelectedIndex;

// Getting selected index value
string index = Session["index"].ToString();

Edited by jugosoft: n/a

0

Thanks for the Reply,

In which event m i going to capture selectedindex

Also, this is not happening with my Other Forms, I m able to capture the selectedvalue for each row of the gridview in my other Forms, under similar conditions

Pls help

Regards
Suresh G

0

In this case, button is problem.

protected void button1_Click(object sender, EventArgs e)
{
    ...

    // Saving SelectedIndex property
    Session["index"] = dropDownList1.SelectedIndex;

    ...
}
0

Both SelectedIndex and SelectedItem is not working, since at Button Click, the dropdownlist Selected Index Changed event is fired and the count of dropdownlist is becoming Zero

0

Do you use the value that we saved or you didn't changed SelectedIndex in code to Session["index"]. Can you post your code?

0

Have you tried to debug application? Try solving with it. Watch for location where SelectedIndex property is restarted.

Do you have a method that removes all rows from DataGrid/DropDownList. In all that methods there must be a code that saves selected index in session.

I solved my problem with session setting in some methods, where I selected item from list and selected index was -1 (default) because of Page_Load event.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.