Use the commandName property and a ButtonField rather than a
CommandField
<asp:GridView runat="server" OnRowCommand="R owCommandHandle r">
<asp:ButtonFiel d CommandName="Se lect1" Text="Select" />
<asp:ButtonFiel d CommandName="Se lect2" Text="Select" />
</asp:GridView>
then in your codebehind use
protected void RowCommandHandl er(object sender, GridViewRowEven tArgs e)
{
if(e.CommandNam e = "Select1")
{
// Do selects for the first datagrid
}
else
{
// Do selects for the second datagrid
}
}
You can get a reference to the row which fired the event with
protected void RowCommandHandl er(object sender, GridViewRowEven tArgs e)
{
int rowIndex = Convert.ToInt32 (e.CommandArgum ent);
GridViewRow selectedRow = (sender as GridView).Rows[rowIndex];
}
or set the CommandArgument yourself as part of your databind. If I'm
doing something like this, I'll usually set the CommandArgument of my
(x)Button to the primary key of the child record I want to select, so I
can do
protected void RowCommandHandl er(..)
{
int childKey = Convert.ToInt32 (e.CommandArgum ent);
if(e.CommandNam e="FirstCommand ")
{
SelectSomeDataF orTheFirstComma nd(childKey);
}
}
HTH,
-- Flinky Wisty Pomm
be**********@sk ynet.be wrote:
I need to be able to make the difference between the two commandfields
because the GridView with the two Commandfields is a master GridView
with two different slave GridViews. It is the click on a CommandField
button that shows one of the two slave GridViews.
How am I able to solve this problem?
Kind regards,
Bert Janssens
Christopher Reed schreef:
Why do you have two Select CommandFields? The purpose of a Select
CommandField is to select the whole row. Please elaborate further as to
what you want to accomplish.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."
<be**********@s kynet.be> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. . Hi,
In ASP.NET 2.0, I have a GridView with 2 CommandFields, how can I
determine in the SelectedIndexCh anged event which CommandField is
clicked?
<asp:GridView ID="gvOrderList " runat="server"
AutoGenerateCol umns="False"
OnSelectedIndex Changed="gvOrde rList_SelectedI ndexChanged">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true" />
<asp:CommandFie ld ShowSelectButto n="true" />
<asp:BoundFie ld DataField="Agen t" SortExpression= "Agent" />
</Columns>
</asp:GridView>
Can anybody solve this problem?
kind regards,