but, note how we STILL have to load up the radiobutton list and ALSO setup the combo box that gives a different set of choices.
So, we add this code to the row data bound event.
protected void GHotels_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView gData = e.Row.DataItem as DataRowView;
// based on Gender fill cbo box
string strSQL = "SELECT ID, Feature FROM tblHotelOptions ";
if (gData["Gender"].ToString() == "M")
{
strSQL = "WHERE Gender = 'M'";
}
else
{
strSQL = "WHERE Gender = 'F'";
}
strSQL = " ORDER BY Feature";
DropDownList cboOption = e.Row.FindControl("cboOption") as DropDownList;
cboOption.DataSource = MyRst(strSQL);
cboOption.DataBind();
cboOption.Items.Insert(0, new ListItem("Select", "0"));
if (gData["HotelOption"] != null)
cboOption.SelectedValue = gData["HotelOption"].ToString();
}
}
So, for each grid row, we process the data row information, and conditional load up the drop down list with choices based on gender.
Now, that works for "loading", but now we need to add the event and code for when we CHANGE the radio button choice.
so, in the markup, we add this event to the radiobutton:
We have to use markup and intel-sense to pop up the choice to create a new event, like this:
So, we added autopostback=true to the radio button list, and the selected change event.
So, now when you change the radio choice, we need to run code to change the drop down list choices.
So, that code can look like this:
protected void RGender_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rBtn = sender as RadioButtonList;
GridViewRow gRow = rBtn.NamingContainer as GridViewRow;
string strSQL = "SELECT ID, Feature FROM tblHotelOptions ";
if (rBtn.SelectedItem.Text == "M")
// based on Gender fill cbo box
{
strSQL = "WHERE Gender = 'M'";
}
else
{
strSQL = "WHERE Gender = 'F'";
}
strSQL = " ORDER BY Feature";
DropDownList cboOption = gRow.FindControl("cboOption") as DropDownList;
cboOption.DataSource = MyRst(strSQL);
cboOption.DataBind();
cboOption.Items.Insert(0, new ListItem("Select", "0"));
}
In fact, the code is VERY much the same as how we had to load up the grid.