Home All Groups Group Topic Archive Search About

Getting row index by Event Args...

Author
2 Sep 2006 8:24 AM
basulasz
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?

Author
2 Sep 2006 3:35 PM
Teemu Keiski
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


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?
>
Are all your drivers up to date? click for free checkup

Author
3 Sep 2006 10:36 AM
basulasz
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?
> >
>
>
>
Author
3 Sep 2006 12:08 PM
basulasz
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?
> >
>
>
>

Bookmark and Share

Post Thread options