Click here to Skip to main content
15,884,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to generate itemcommand event for radiobuttonlist inside repeater.

I used commandname property but its not working.

Please help me.

aspxcode

<asp:RadioButtonList ID="rdWittenDeclined" runat="server" RepeatDirection="Horizontal" SelectedValue='<%# Eval("WrittenOrRejected") %>' CausesValidation="false" CommandName="Update" AutoPostBack="true" >
<asp:ListItem Value="N/A" Text="N/A" Enabled="false">
<asp:ListItem Value="DeclinedByCompany" Text="Declined By Company">
<asp:ListItem Value="DeclinedByCustomer" Text="Declined By Customer">
<asp:ListItem Value="Written" Text="Written">


c# code

if (e.CommandName == "Radio")
{
//set the hidden text boxes
txtAddType.Text = "AdditionalInsured";
txtPolicyInfoIDAddPop.Text = ((TextBox)e.Item.FindControl("txtPolicyInfoID")).Text.ToString();
ScriptManager.RegisterStartupScript(this, typeof(string), "open", "$('#additional-details').dialog('open');", true);
GetAdditionalInfoGeneral();
GetAdditionalInfoGrid();
}
Posted
Updated 19-Feb-13 20:45pm
v2
Comments
Sandeep Mewara 20-Feb-13 2:33am    
You should share what you tried and is 'not working'. Update question using 'Improve question' link.

Hi

Once radiobuttonlist render to client its unable to call server side event for control like radiobuttonlist.Also it will make performance impact.Best way is
Register client side onclick event and you can get radionbutton object with selected item
save it in hiddenfield and then on server click use that values.
XML
<asp:radiobuttonlist id="rdlLst" runat="server" onselectedindexchanged="IndexChanged" xmlns:asp="#unknown">
   <asp:listitem text="1" onclick="Test(this);"></asp:listitem>
   <asp:listitem text="2"></asp:listitem>
   <asp:listitem text="3"></asp:listitem>
</asp:radiobuttonlist>
<script type="text/javascript">
function Test(obj)
{
   alert('here');
}
</script>

Please let me know if this helpful.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 21-Feb-13 20:58pm    
As a note, please use the "Improve Solution" widget on your original solution when you have more information to add to a solution as it helps keep things clean and organized. Please don't add a new solution each time.
You will not directly get event of item command.You have one more way to do.
Register SelectedIndexChange event of radiobuttonlist
write below code so that you can get control value in Repeater control row

protected void IndexChanged(Object Sender, EventArgs e)
{
RadioButtonList lst = (RadioButtonList)Sender;
Label2.Text = lst.Parent.Controls[1].ToString();// this line will give text of selected row controls value
}


Please let me know if this will help you.
 
Share this answer
 
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
rptColors.DataSource = new List<colours> { new Colours { Color = "Red" }, new Colours { Color = "Black" } };
rptColors.DataBind();
}
}

protected void Checked(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptColors.Items)
{
RadioButton rdbColour = item.FindControl("rdbColour") as RadioButton;
if (rdbColour.Text.Equals((sender as RadioButton).Text))
{
CommandEventArgs commandArgs = new CommandEventArgs("SomeCommand", rdbColour.Text);
RepeaterCommandEventArgs repeaterArgs = new RepeaterCommandEventArgs(item, rdbColour, commandArgs);
rptColors_ItemCommand(rdbColour, repeaterArgs);
}
}
}

protected void rptColors_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//Runs when you select the radio button in the repeater
System.Diagnostics.Debugger.Break();
}
}



i used this code now i got answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900