Click here to Skip to main content
11,410,550 members (60,159 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Radbutton
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 19-Feb-13 20:11pm
Edited 19-Feb-13 21:45pm
v2
Comments
Sandeep Mewara at 20-Feb-13 2:33am
   
You should share what you tried and is 'not working'. Update question using 'Improve question' link.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
<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.
  Permalink  
v2
Comments
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
rptColors.DataSource = new List { 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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,885
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100