|
Subject:
|
help related to a SelectedIndexChanged event
|
|
Posted By:
|
suneet.pant
|
Post Date:
|
5/14/2008 6:47:44 AM
|
help related to a SelectedIndexChanged event of a dropdownlist inside a GridView control in asp.net 2.0
I am using asp.net 2.0. I have a dropdownlist control inside a gridview control. On selecting an item in the dropdownlist, I am able to display related data in other two columns of the grid in the same row. But the problem -> the moment i choose another item from the dropdownlist data just get cleared from the previous line. This is happening in every row.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string selectedtext = ((DropDownList) GridView1.SelectedRow.FindControl ("ddlicode")).SelectedItem.Value; GridViewRow row = GridView1.SelectedRow;
comm = new SqlCommand("select item_code,item_desc from ItemMast where item_desc='" + selectedtext + "'", conn); conn.Open(); SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { ((Label)row.FindControl("lblicode")).Text = dr.GetValue (0).ToString().Trim(); ((Label)row.FindControl("lblidesc")).Text = dr.GetValue (1).ToString().Trim(); } conn.Close(); }
|
|
Reply By:
|
Quick209
|
Reply Date:
|
5/22/2008 4:41:44 PM
|
Here is what I think maybe going on. I have been off PCs for 4 months thanks to optic neuritis so I am feeling a little rusty.
I had a gridview that updated its datasource via code. I wanted to export that to an excel file so I tried to tell the new virtual datagrid to use the same datasource as the grid that is being displayed. Wanna know what I found? I found no data in there. Anybody can correct me but if there is no datasource on the front end (html side) or it isn't getting fed the data source and then you get it from the control after that in the same instance then it will not be retained. Similar to variables losing their value after the page comes back. You may have to save the state of that Gridview during the initial alteration before the system returns everything to the page. Basically, after your update, save the state in a session or database and then call it back in front to repopulate if it is not an empty session. The state of that control is not being saved. Now, I am rusty on viewstates also but I heard there might be a way to tell the control to hold on to its state but the rest of the forum who has been actively programming for the past 4 months can answer that, I have to get caught up so I don't look like an idiot when I return to work. :)
|