|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting row index by Event Args...I created a radio button dynamically in a row of a Grid View control. I
enabled auto post back property of this radio button to execute a code. For example , I create 20 rows and I want to know about which button is checked. How can i get the index of that row? Hi,
you of course handle RadioButton's CheckedChanghed event. In the event cast 'sender' as CheckBox (it's the CB raising the event). Then you get the current GridViewRow via NamingContainer property of the RadioButton. For example protected void RadioButton_CheckedChanged(object sender, EventArgs e) { RadioButton btn=(RadioButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; //Now you can get row index etc via the row object } And this event handler has been wired to the CB in aspx (in GridView TemplateField) like <asp:RadioButton OnCheckedChanged="RadioButton_CheckedChanged" ... /> Show quoteHide quote "basulasz" <basul***@discussions.microsoft.com> wrote in message news:0AAE81F5-E870-4607-AF1C-344B358BF9EF@microsoft.com... >I created a radio button dynamically in a row of a Grid View control. I > enabled auto post back property of this radio button to execute a code. > For > example , I create 20 rows and I want to know about which button is > checked. > How can i get the index of that row? > Hi Teemu;
Firstly thanks. I have tried that you written, but i thing there is missing here. let me to say what I do and correct me if there is something wrong. I have enabled AutoPostBack property as true. And written code for CheckedChanged event of RadioButton. And tried to print the row index as below public void rdV_CheckedChanged(object sender, EventArgs e) { RadioButton btn = (RadioButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; Label1.Text = row.DataItemIndex.ToString(); } But when i click the RadioButton I go to next page and only see unchecked RadioButtons and empty Label1. I do not understand what is wrong with that? Show quoteHide quote "Teemu Keiski" wrote: > Hi, > > you of course handle RadioButton's CheckedChanghed event. In the event cast > 'sender' as CheckBox (it's the CB raising the event). Then you get the > current GridViewRow via NamingContainer property of the RadioButton. > > For example > > protected void RadioButton_CheckedChanged(object sender, EventArgs e) > { > RadioButton btn=(RadioButton)sender; > GridViewRow row = (GridViewRow)btn.NamingContainer; > //Now you can get row index etc via the row object > } > > And this event handler has been wired to the CB in aspx (in GridView > TemplateField) like <asp:RadioButton > OnCheckedChanged="RadioButton_CheckedChanged" ... /> > > -- > Teemu Keiski > ASP.NET MVP, AspInsider > Finland, EU > http://blogs.aspadvice.com/joteke > > > "basulasz" <basul***@discussions.microsoft.com> wrote in message > news:0AAE81F5-E870-4607-AF1C-344B358BF9EF@microsoft.com... > >I created a radio button dynamically in a row of a Grid View control. I > > enabled auto post back property of this radio button to execute a code. > > For > > example , I create 20 rows and I want to know about which button is > > checked. > > How can i get the index of that row? > > > > > I have tried the same thing with ImageButton, and I am done with that.
Thanks for help... Show quoteHide quote "Teemu Keiski" wrote: > Hi, > > you of course handle RadioButton's CheckedChanghed event. In the event cast > 'sender' as CheckBox (it's the CB raising the event). Then you get the > current GridViewRow via NamingContainer property of the RadioButton. > > For example > > protected void RadioButton_CheckedChanged(object sender, EventArgs e) > { > RadioButton btn=(RadioButton)sender; > GridViewRow row = (GridViewRow)btn.NamingContainer; > //Now you can get row index etc via the row object > } > > And this event handler has been wired to the CB in aspx (in GridView > TemplateField) like <asp:RadioButton > OnCheckedChanged="RadioButton_CheckedChanged" ... /> > > -- > Teemu Keiski > ASP.NET MVP, AspInsider > Finland, EU > http://blogs.aspadvice.com/joteke > > > "basulasz" <basul***@discussions.microsoft.com> wrote in message > news:0AAE81F5-E870-4607-AF1C-344B358BF9EF@microsoft.com... > >I created a radio button dynamically in a row of a Grid View control. I > > enabled auto post back property of this radio button to execute a code. > > For > > example , I create 20 rows and I want to know about which button is > > checked. > > How can i get the index of that row? > > > > >
Really Stuck on a Canlendar Control PLEASE HELP!!!
Javascript disabled Menu control Accessibility I am trying to hide some textboxes, dropdownlists and labels in datalist UserControl values lost on PostBack Video Player in browser... how do I do? Shuffling rows in a GridView DetailsView Issue. Data diagrams - like the ones in office (excel, word, et al.) CustomWeb Controls and Events I want to know what is a Functional Specification Document? |
|||||||||||||||||||||||