troubleshooting Question

How to reset a radiobutton that was created as a literal in a gridview when a selectedindexchange event occurs in a DDL

Avatar of reedsster1
reedsster1 asked on
.NET ProgrammingASP.NETVisual C++.NET
12 Comments1 Solution994 ViewsLast Modified:
Hello
I have a run of drop down lists with auto postback enabled that run stored procedures to populate the information into the next drop down list.  The final drop down lists passes the selected information into a gridview which creates a radiobutton within the gridview using the literal control.  
I am having a slight problem.
Once the gridview has been created, if I select a value, then change the DDL that loads the gridview, I get an error:
Line 104:                return -1;
Line 105:            else
Line 106:                return Convert.ToInt32(Request.Form["OptionsGroup"]);
Line 107:        }
Line 108:    }

I assume this is because the radiobutton is trying to remain checked.  How do I clear this gridview?  The C# code behind does not recognize the radiobutton control.  
I have the DDL's clearing each other like so:
 protected void YearDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {

        MakeDropDownList.Items.Clear();
        MakeDropDownList.Items.Insert(0, new ListItem("Select A Make", "0"));
        MakeDropDownList.SelectedValue = "0";
        ModelDropDownList.Items.Clear();
        ModelDropDownList.Items.Insert(0, new ListItem("Select A Model", "0"));
        ModelDropDownList.SelectedValue = "0";
     
       
        PartDropDownList.SelectedValue = "0";


Is it possible to do something similar to this radiobutton?  Here is the code for the gridview:
<td align="left" colspan="3" style="width: 533px; height: 41px" valign="middle">
                         &nbsp;<asp:GridView ID="OptionsGridView" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource5" DataKeyNames="Application" OnRowDataBound="OptionsGridView_RowDataBound" GridLines="None" Width="541px">
                             <Columns>
                                 
                                 ...
                                 <asp:TemplateField HeaderText="Select:">
                                     <ItemTemplate>
                                         &nbsp;<asp:Literal ID="RadioButtonMarkup" runat="server"></asp:Literal>
                                   
                                     </ItemTemplate>
                                 </asp:TemplateField>                                                              
                                                           </Columns>
                         </asp:GridView>
Here is the code behind to create the radiobutton:

private int OptionsSelectedIndex
    {
        get
        {
            if (string.IsNullOrEmpty(Request.Form["OptionsGroup"]))
                return -1;
            else
                return Convert.ToInt32(Request.Form["OptionsGroup"]);
        }
    }


    protected void OptionsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            {
                // Grab a reference to the Literal control
                Literal output = (Literal)e.Row.FindControl("RadioButtonMarkup");
                // Output the markup except for the "checked" attribute
                output.Text = string.Format("<input type='radio' runat='server' name='OptionsGroup' id='RowSelector{0}' value='{0}'", e.Row.Cells[1].Text);
                // See if we need to add the "checked" attribute
                if (OptionsSelectedIndex == e.Row.RowIndex)
                    output.Text += " checked='checked'";
                // Add the closing tag
                output.Text += " />";
            }
          }

Any help would be appreciated!
Thanks

ASKER CERTIFIED SOLUTION
CmdoProg2

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros