473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView question

I have a grid view with a button field that when clicked I want it to
redirect to another page, passing the primary key of the row with it.
This was a pretty easy thing to do with the DataGrid, but it is so far
proving a pain with the GridView.

Here is my button :

<asp:ButtonFiel d ButtonType="Ima ge" ImageUrl="~/Images/btnDetails.jpg"
CommandName="Op portunityDetail s" />

In the GridView DataKeyNames is set like this :

DataKeyNames="O pportunityID"

And I am trying to redirect using this code :

protected void GridView1_RowCo mmand(object sender,
GridViewCommand EventArgs e)
{
if (e.CommandName == "OpportunityDet ails")
{
//get PK (opportunityID)
int intOppID = Convert.ToInt32 (e.CommandArgum ent);

Response.Redire ct("Opportunity Details.aspx?op pid=" +
intOppID);
}
}

Instead of the PrimaryKey being passed, I just get the GridView index
passed (for the first row 0 is passed, for the second row 1 is passed
etc).

There must be a simple solution to this, I'm hoping somebody can tell me
what it is!

*** Sent via Developersdex http://www.developersdex.com ***
Apr 26 '06 #1
2 991
instead of the datakeynames you might want to use selected
gridview1.selec tedDataKey or selectedValue

Apr 26 '06 #2
What is the syntax for getting the SelectedDataKey for the selected row?
*** Sent via Developersdex http://www.developersdex.com ***
Apr 26 '06 #3

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

Similar topics

3
5666
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
6
3027
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
4
2611
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I re-format the updated row fields. I have looked at gridView.rowUpdated method, but cannot figure out how....
7
14790
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1...
1
3227
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a...
4
1806
by: Chris | last post by:
Hi, I read about client callback and i have a question. Assume the option "sorting" is set in a gridview. Each time the user clicks on a fieldname, the data are sorted. My question is: are the data on each click fetched from the server, or are they 'cached' on the client-side and so avoiding a lot of transferts between server and...
3
311
by: Gonza | last post by:
Hi group, i have a question relatred to gridview and postback (i should probably know this by now, considering i've been working with .net for a few years now, but baahh). Why could a gridview (regular gridview, no custom controls inside, bound to a list<custom object>) loose it's value after a postback. I know that the datasource is not saved...
1
8557
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but it doesn't seem to work at all. Below is my ASP.NET page, and further below, my VB.NET method that I am trying to call: <div id="admin-faq"...
4
11133
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim ReportTable As System.Data.DataTable = New System.Data.DataTable("SendTo") The ReportTable is populated row by row by data gotten back from the
1
1622
by: Cirene | last post by:
This is confusing... I have a gridview (gv1) with another gridview (gv2) inside of it. gv1 has a bunch of house listings and within each row is a group of related house pictures (gv2). I'm having trouble getting gv2 to show any data. Here's part of my code...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
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
6263
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...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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
3643
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
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
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.