Displaying a passed value from a previous page in a databound DDL
-
I need to display a value passed through a session variable to a DropDownList that is already bound to a DB table and do the same to a dependent child DDL. I hope I'm explaining this clearly. In essence I have two DDLs bound to two separate data tables. The value selected on the first DDL will 'filter' out and display only related values in the second DDL. This much is working fine. Now, what I need is to have the first DDL display a value passed through a session variable from a previous page on both DDLs so that the user begins an update session with valid current information. It shouldn't be so hard to accomplish but I haven't had much luck on this one, yet. I have read a few threads on this forum but it isn't clear to me how to apply the statement: .SelectedIndex = .Items.IndexOf(.Items.FindByValue(etc etc etc ) I'm not even working in a backcode environment as all my pages are inline coded. Any help on this subject would be deeply appreciated. a-c
-
I need to display a value passed through a session variable to a DropDownList that is already bound to a DB table and do the same to a dependent child DDL. I hope I'm explaining this clearly. In essence I have two DDLs bound to two separate data tables. The value selected on the first DDL will 'filter' out and display only related values in the second DDL. This much is working fine. Now, what I need is to have the first DDL display a value passed through a session variable from a previous page on both DDLs so that the user begins an update session with valid current information. It shouldn't be so hard to accomplish but I haven't had much luck on this one, yet. I have read a few threads on this forum but it isn't clear to me how to apply the statement: .SelectedIndex = .Items.IndexOf(.Items.FindByValue(etc etc etc ) I'm not even working in a backcode environment as all my pages are inline coded. Any help on this subject would be deeply appreciated. a-c
What about DDL.SelectedValue = "Your value"?
-
What about DDL.SelectedValue = "Your value"?
Thanks for replying. The "Your value" is a string and what the SelectedValue attribute needs is an index (0,1,2,3) for the assignment to work, which I'm almost positive there's a way of getting without looping over a dataset and finding it that way. As of the past few days I've been reading about the FindByValue and IndexOf in uses such as: ddlDivName.Items.FindByValue (drDiv.getValue().ToString()).Selected = True but I'm not sure where to plug in the string value in my session variable. As it is the compiler returns: System.InvalidOperationException: Invalid attempt to read when no data is present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at ASP.appDetailEdit_aspx.Page_Load It shouldn't have to be so hard, right?