473,543 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET 2.0 problem with a GridView with 2 CommandFields

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,

Jan 5 '06 #1
4 9781
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,

Jan 6 '06 #2
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,


Jan 16 '06 #3
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,


Jan 16 '06 #4
Nevermind, I solved the problem by using two ButtonFields with the
parameter CommandName.

Thanks anyway.

Jan 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5663
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the GridView to allow entry of quantity and Y/N switch for
1
1904
by: ABC | last post by:
I have an idea. I need to write a common gridview block which contains labels, textboxs, one girdview and some buttons. Then, I think the above block will apply on several girdview with different columns, for example: Common GridView Block - label, textboxs, buttons - one girdview without any columns
0
1159
by: SR | last post by:
Hi, if I want to put two select commandfields in a gridview like below, how can I find which one was clicked in the SelectedIndexChanged event ? <Columns> <asp:CommandField ButtonType="Link" SelectText="Choose" ShowSelectButton="true" /> <asp:CommandField ButtonType="Link" SelectText="Info" ShowSelectButton="true" /> <asp:BoundField...
1
9337
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
2
6239
by: nolan | last post by:
I have an asp.net 2.0 page with a gridview and detailsview on the same page set up in a master-details scenario. The gridview and detailsview have separate SQL data sources. The user enters search criteria in a text box and clicks a find button to initially populate the gridview with items of interest. I have added a select button to my...
1
5206
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView...
0
1012
by: Uriah Piddle | last post by:
Hi Gang, In a GridView, I have some asp:CommandFields and then some regular asp controls like this: <grid view> <columns> ... a few command fields <templatefield> <itemtemplate>
0
2126
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a...
4
9769
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the...
0
7399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7729
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3385
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.