Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > gridview row command

Reply
Thread Tools

gridview row command

 
 
=?Utf-8?B?Tkg=?=
Guest
Posts: n/a
 
      04-18-2006
How do I find out the row index selected in the gridveiw row command method?

I have an imageButton in a gridview cell and its corresponding code in the
row command method needs to know the row index in question in order to set
the background of the cell to a different color. But the selectedIndex value
doesnt return a value as expected.

Is there something I am missing?
 
Reply With Quote
 
 
 
 
Pipo
Guest
Posts: n/a
 
      04-18-2006
You can use the SelectedDataKey property to retrieve the DataKey object for
the currently selected row. You can also use the SelectedValue property to
retrieve the data key value for the currently selected row directly.



"NH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How do I find out the row index selected in the gridveiw row command
> method?
>
> I have an imageButton in a gridview cell and its corresponding code in the
> row command method needs to know the row index in question in order to set
> the background of the cell to a different color. But the selectedIndex
> value
> doesnt return a value as expected.
>
> Is there something I am missing?



 
Reply With Quote
 
 
 
 
=?Utf-8?B?Tkg=?=
Guest
Posts: n/a
 
      04-18-2006
thanks, but that wont let me know which row index was selected..?

"Pipo" wrote:

> You can use the SelectedDataKey property to retrieve the DataKey object for
> the currently selected row. You can also use the SelectedValue property to
> retrieve the data key value for the currently selected row directly.
>
>
>
> "NH" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > How do I find out the row index selected in the gridveiw row command
> > method?
> >
> > I have an imageButton in a gridview cell and its corresponding code in the
> > row command method needs to know the row index in question in order to set
> > the background of the cell to a different color. But the selectedIndex
> > value
> > doesnt return a value as expected.
> >
> > Is there something I am missing?

>
>
>

 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      04-18-2006
not?
Search for the row with the same id and you'll know the row, right?
(row.FindControl("imagebutton") for the imagebutton or search for the cell
where the imagebutton is in.


"NH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> thanks, but that wont let me know which row index was selected..?
>
> "Pipo" wrote:
>
>> You can use the SelectedDataKey property to retrieve the DataKey object
>> for
>> the currently selected row. You can also use the SelectedValue property
>> to
>> retrieve the data key value for the currently selected row directly.
>>
>>
>>
>> "NH" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > How do I find out the row index selected in the gridveiw row command
>> > method?
>> >
>> > I have an imageButton in a gridview cell and its corresponding code in
>> > the
>> > row command method needs to know the row index in question in order to
>> > set
>> > the background of the cell to a different color. But the selectedIndex
>> > value
>> > doesnt return a value as expected.
>> >
>> > Is there something I am missing?

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Tkg=?=
Guest
Posts: n/a
 
      04-18-2006
The SelectedDataKey only holds the datakey of the datasource, this is not the
same as the row index, the datakey could be a customerID which is not going
to be the same as the row index. Or am I mistaken?

"Pipo" wrote:

> not?
> Search for the row with the same id and you'll know the row, right?
> (row.FindControl("imagebutton") for the imagebutton or search for the cell
> where the imagebutton is in.
>
>
> "NH" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > thanks, but that wont let me know which row index was selected..?
> >
> > "Pipo" wrote:
> >
> >> You can use the SelectedDataKey property to retrieve the DataKey object
> >> for
> >> the currently selected row. You can also use the SelectedValue property
> >> to
> >> retrieve the data key value for the currently selected row directly.
> >>
> >>
> >>
> >> "NH" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > How do I find out the row index selected in the gridveiw row command
> >> > method?
> >> >
> >> > I have an imageButton in a gridview cell and its corresponding code in
> >> > the
> >> > row command method needs to know the row index in question in order to
> >> > set
> >> > the background of the cell to a different color. But the selectedIndex
> >> > value
> >> > doesnt return a value as expected.
> >> >
> >> > Is there something I am missing?
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Pipo
Guest
Posts: n/a
 
      04-19-2006
No you are right, sorry
What I always do is that I have a column (visible = false) with the unique
record ID.
With that I can find the row which was selected.
I was in the wrong assumpsion you did that also.



"NH" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The SelectedDataKey only holds the datakey of the datasource, this is not
> the
> same as the row index, the datakey could be a customerID which is not
> going
> to be the same as the row index. Or am I mistaken?
>
> "Pipo" wrote:
>
>> not?
>> Search for the row with the same id and you'll know the row, right?
>> (row.FindControl("imagebutton") for the imagebutton or search for the
>> cell
>> where the imagebutton is in.
>>
>>
>> "NH" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > thanks, but that wont let me know which row index was selected..?
>> >
>> > "Pipo" wrote:
>> >
>> >> You can use the SelectedDataKey property to retrieve the DataKey
>> >> object
>> >> for
>> >> the currently selected row. You can also use the SelectedValue
>> >> property
>> >> to
>> >> retrieve the data key value for the currently selected row directly.
>> >>
>> >>
>> >>
>> >> "NH" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> > How do I find out the row index selected in the gridveiw row command
>> >> > method?
>> >> >
>> >> > I have an imageButton in a gridview cell and its corresponding code
>> >> > in
>> >> > the
>> >> > row command method needs to know the row index in question in order
>> >> > to
>> >> > set
>> >> > the background of the cell to a different color. But the
>> >> > selectedIndex
>> >> > value
>> >> > doesnt return a value as expected.
>> >> >
>> >> > Is there something I am missing?
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
JBorders JBorders is offline
Junior Member
Join Date: Apr 2007
Posts: 1
 
      04-17-2007
You can access the row index from within the RowCommand by using the e.CommandArgument property. "e" is the passed GridViewCommandEventArgs parameter to the RowCommand method. GridView will automatically set the CommandArgument inside this parameter to the index of the row where the command occurred (which may NOT neccessarily be the "selected" row!).

int index = Convert.ToInt32(e.CommandArgument);

Hope this helps.
 
Reply With Quote
 
nikitagon nikitagon is offline
Junior Member
Join Date: Dec 2009
Posts: 1
 
      12-08-2009
Reply is here blogs. ipona.com /davids/archive/2007/11/22/8447.aspx:

<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="IncreasePriceButton" runat="server"
Text="+10%"
CommandName="IncreasePrice"
CommandArgument='<%# Container.DataItemIndex %>' />
<asp:Button ID="DecreasePriceButton" runat="server"
Text="-10%"
CommandName="DecreasePrice"
CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
 
Reply With Quote
 
nick5454 nick5454 is offline
Junior Member
Join Date: Feb 2008
Posts: 2
 
      03-09-2010
Quote:
Originally Posted by nikitagon
Reply is here blogs. ipona.com /davids/archive/2007/11/22/8447.aspx:

<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="IncreasePriceButton" runat="server"
Text="+10%"
CommandName="IncreasePrice"
CommandArgument='<%# Container.DataItemIndex %>' />
<asp:Button ID="DecreasePriceButton" runat="server"
Text="-10%"
CommandName="DecreasePrice"
CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>

Asp:buttonfield does the exact same thing with less markup
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview row databound event - can't get past the 1st row of gridview maurban@gmail.com ASP .Net 5 10-13-2006 09:37 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
Selecting a row in asp.net 2.0 GridView by clicking anywhere in the row misiek ASP .Net 0 02-20-2006 08:26 AM
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM
Highlight the row and click anywhere to select a row in a GridView Fernando Lopes ASP .Net 0 04-28-2005 12:24 PM



Advertisments