reedsster1
asked on
How to reset a radiobutton that was created as a literal in a gridview when a selectedindexchange event occurs in a DDL
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.Fo rm["Option sGroup"]);
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_SelectedI ndexChange d(object sender, EventArgs e)
{
MakeDropDownList.Items.Cle ar();
MakeDropDownList.Items.Ins ert(0, new ListItem("Select A Make", "0"));
MakeDropDownList.SelectedV alue = "0";
ModelDropDownList.Items.Cl ear();
ModelDropDownList.Items.In sert(0, new ListItem("Select A Model", "0"));
ModelDropDownList.Selected Value = "0";
PartDropDownList.SelectedV alue = "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">
<asp:GridView ID="OptionsGridView" runat="server" AutoGenerateColumns="False " DataSourceID="SqlDataSourc e5" DataKeyNames="Application" OnRowDataBound="OptionsGri dView_RowD ataBound" GridLines="None" Width="541px">
<Columns>
...
<asp:TemplateField HeaderText="Select:">
<ItemTemplate>
<asp:Literal ID="RadioButtonMarkup" runat="server"></asp:Liter al>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is the code behind to create the radiobutton:
private int OptionsSelectedIndex
{
get
{
if (string.IsNullOrEmpty(Requ est.Form[" OptionsGro up"]))
return -1;
else
return Convert.ToInt32(Request.Fo rm["Option sGroup"]);
}
}
protected void OptionsGridView_RowDataBou nd(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
{
// Grab a reference to the Literal control
Literal output = (Literal)e.Row.FindControl ("RadioBut tonMarkup" );
// 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
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.Fo
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_SelectedI
{
MakeDropDownList.Items.Cle
MakeDropDownList.Items.Ins
MakeDropDownList.SelectedV
ModelDropDownList.Items.Cl
ModelDropDownList.Items.In
ModelDropDownList.Selected
PartDropDownList.SelectedV
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">
<asp:GridView ID="OptionsGridView" runat="server" AutoGenerateColumns="False
<Columns>
...
<asp:TemplateField HeaderText="Select:">
<ItemTemplate>
<asp:Literal ID="RadioButtonMarkup" runat="server"></asp:Liter
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is the code behind to create the radiobutton:
private int OptionsSelectedIndex
{
get
{
if (string.IsNullOrEmpty(Requ
return -1;
else
return Convert.ToInt32(Request.Fo
}
}
protected void OptionsGridView_RowDataBou
{
if (e.Row.RowType == DataControlRowType.DataRow
{
{
// Grab a reference to the Literal control
Literal output = (Literal)e.Row.FindControl
// 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
Changed things around to be more in line with your code. Still getting an error:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 51: { return -1; }
Line 52: else
Line 53: { return Convert.ToInt32(Request.Fo rm["Option sGroup"]); }
Line 54: }
Line 55:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 51: { return -1; }
Line 52: else
Line 53: { return Convert.ToInt32(Request.Fo
Line 54: }
Line 55:
Check your data to ensure the value of the input radio control is an Int32. Your InventoryNbr field may contain non-numeric characters such as 32-32345, 2345H349 or larger value than 32 bits.
A sledgehammer test to isolate the problem would to replace line 53 with the snippet below, but a try..catch would be preferred for operations:
{
string optionsGroup = Request.Form["OptionsGroup "]
return Convert.ToInt32(optionsGro up);
}
A sledgehammer test to isolate the problem would to replace line 53 with the snippet below, but a try..catch would be preferred for operations:
{
string optionsGroup = Request.Form["OptionsGroup
return Convert.ToInt32(optionsGro
}
ASKER
It does. InventoryNbr is a varchar and contains alpha numeric's. Does that change how I should have any of this formatted?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome! I'm one step closer to my site being live!
ASKER
That worked like a charm. The only problem I have with this function still is that the radio button remains checked even when the values change. I should be able to figure that one out on my own though. Thanks!
Scott
Scott
ASKER
Actually, still having a bit of trouble. The value getting pulled into the varible I am trying to pass onto the next page (InventoryNbr) is now just the row number (0,1,2,3,4 ETC)
I am getting it via:
string INVNUM = Request.Form["OptionsGroup "];
Any idea?
I am getting it via:
string INVNUM = Request.Form["OptionsGroup
Any idea?
ASKER
Ok, I see that you covered that in your answer, I shouldn't have been so quick to act here. How can I get it to return InventoryNbr still in my
string INVNUM = Request.Form["OptionsGroup "];
and still get the gridview to reset when the prior DDL is changed without the error?
string INVNUM = Request.Form["OptionsGroup
and still get the gridview to reset when the prior DDL is changed without the error?
ASKER
I've posted a related question with updated and consolidated information.
https://www.experts-exchange.com/Programming/Languages/.NET/newQuestionWizardRelated.jsp?qid=25195209
https://www.experts-exchange.com/Programming/Languages/.NET/newQuestionWizardRelated.jsp?qid=25195209
ASKER
Just isn't my day. Wouldn't let me make such a similar question as a related question, so it's here:
https://www.experts-exchange.com/questions/25197587/How-to-reset-a-radiobutton-that-was-created-as-a-literal-in-a-gridview-when-a-selectedindexchange-event-occurs-in-a-DDL.html?fromWizard=true
https://www.experts-exchange.com/questions/25197587/How-to-reset-a-radiobutton-that-was-created-as-a-literal-in-a-gridview-when-a-selectedindexchange-event-occurs-in-a-DDL.html?fromWizard=true
ASKER
Nevermind, I was able to get it to work as I intended by removing the optionsselectedindex event completely and putting:
OptionsGridView.DataSource = null;
OptionsGridView.DataBind() ;
to the selectedindexchanged event for the DDL that creates the gridview, it solves all my problems. Thanks again for your input.
OptionsGridView.DataSource
OptionsGridView.DataBind()
to the selectedindexchanged event for the DDL that creates the gridview, it solves all my problems. Thanks again for your input.
Open in new window