Reputation: 407
I have a set of three RadioButtons
on my aspx page:
On pageLoad
I am setting the default value from code behind using the following code:
rbListAccess.Items.FindByText("Page1ScoreCard POC").Selected = true;
rbListMetricType.Items.FindByText("Non-Percentage").Selected = true;
rbListMetricInterval.Items.FindByText("Monthly").Selected = true;
This is working fine.
On an edit link,I am fetching data from backend and setting values again using data columns from the dataset fetched but there it is not working. The values are not being selected correctly. I cannot understand the issue. Randomly once or twice one/two of the set are being set correctly:
rbListAccess.Items.FindByText(ds.Tables[0].Rows[0]["ToBeFilledBy"].ToString()).Selected = true;
rbListMetricType.Items.FindByText(ds.Tables[0].Rows[0]["MetricType"].ToString()).Selected=true;
rbListMetricInterval.Items.FindByText(ds.Tables[0].Rows[0]["MetricInterval"].ToString()).Selected = true;
Please let me know the issue.
Upvotes: 0
Views: 2748
Reputation: 4892
You might want to clear selection using ClearSelection()
method before you assigning it a new value.
rbListAccess.ClearSelection(); // add this for all your radiobuttons
rbListMetricType.ClearSelection();
rbListMetricType.ClearSelection();
rbListAccess.Items.FindByText(ds.Tables[0].Rows[0]["ToBeFilledBy"].ToString()).Selected = true;
rbListMetricType.Items.FindByText(ds.Tables[0].Rows[0]["MetricType"].ToString()).Selected=true;
rbListMetricInterval.Items.FindByText(ds.Tables[0].Rows[0]["MetricInterval"].ToString()).Selected = true;
Upvotes: 1