|
-
Mar 20th, 2007, 04:15 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Gridview and link button
Hi all
I have a gridview control bind to sql server. I have 6 column names on my grid and 1 additional column which is a link button named 'view'. When data is generated, i want to click on the 'view' link button and show the particular details for that row. (Eg.First column is ID, means show details of the ID).
I want to know how can i do that and how to write the code for the link button.
Many thanks.
-
Mar 21st, 2007, 02:57 PM
#2
Re: [2005] Gridview and link button
Create a new page which will show the details of the data row clicked, say showdetails.aspx
Have showdetails.aspx accept a querystring parameter which will be passed to it as a result of clicking one of the hyperlinks.
You will of course also need to modify the NavigateURL properties of the hyperlinks in your hyperlink column. To do this, handle the GridView's RowDataBound event. It is hit once for each row in the GridView, so you can find the hyperlink control using something like
e.Row.Cells[6].FindControl("hylDetails")
But make sure to cast it to the type HyperLink first, before you modify its NavigateUrl property to be something like
"showdetails.aspx?id=" + strID;
-
Mar 21st, 2007, 07:02 PM
#3
Thread Starter
Member
Re: [2005] Gridview and link button
I have figured it out using a link button as the databound data. Thanks mate anyway.
-
Mar 23rd, 2007, 12:35 PM
#4
Re: [RESOLVED] [2005] Gridview and link button
That's pretty much the same thing but I generally prefer my method for more flexibility.
-
Mar 23rd, 2007, 10:34 PM
#5
Hyperactive Member
Re: [RESOLVED] [2005] Gridview and link button
 Originally Posted by mendhak
That's pretty much the same thing but I generally prefer my method for more flexibility.
Well for flexibility, yes, but in your itemtemplate you can simply set the NavigateUrl property like this:
NavigateUrl='<%# Eval("MyId", "showdetails.aspx?MyId={0}"') %>'
for simplicity sake.
If this post helps, please RATE MY POST!
Using Visual Studio 2005 SE
-
Mar 25th, 2007, 06:36 AM
#6
Re: [RESOLVED] [2005] Gridview and link button
Let me add maintainability, scalability and babadoobalibility to my list.
-
Apr 4th, 2007, 11:42 AM
#7
Lively Member
Re: [RESOLVED] [2005] Gridview and link button
 Originally Posted by kayos
Well for flexibility, yes, but in your itemtemplate you can simply set the NavigateUrl property like this:
NavigateUrl='<%# Eval("MyId", "showdetails.aspx?MyId={0}"') %>'
for simplicity sake. 
Can this be used for more then one field? ie MyId2 as well?
'<%# Eval("MyId", "MyId2" "showdetails.aspx?MyId={0}?????????"') %>'
Bert
___________________________________________
-
Apr 4th, 2007, 03:26 PM
#8
Hyperactive Member
Re: [RESOLVED] [2005] Gridview and link button
 Originally Posted by AlphaOne
Can this be used for more then one field? ie MyId2 as well?
'<%# Eval("MyId", "MyId2" "showdetails.aspx?MyId={0}?????????"') %>'
no, unfortunately this is a single field solution.
if you want multifield then you will have to use something like what mendhak was talking about.
If this post helps, please RATE MY POST!
Using Visual Studio 2005 SE
-
Apr 4th, 2007, 03:43 PM
#9
Lively Member
Re: [RESOLVED] [2005] Gridview and link button
Hmmm....thats not realy true I did this:
<%# String.Format("reserve.aspx?Id={0}&PID={1}", DataBinder.Eval(Container.DataItem,"ID"), DataBinder.Eval(Container.DataItem,"PropertyId")) %>
This can be extended as long as you will need:-)
Bert
Bert
___________________________________________
-
Apr 6th, 2007, 03:29 AM
#10
Re: [RESOLVED] [2005] Gridview and link button
That code actually made me shudder.
I don't think people actually understand the negatives of inserting values that way.
-
Apr 6th, 2007, 07:42 AM
#11
Lively Member
Re: [RESOLVED] [2005] Gridview and link button
Maybe you explane why this is negative. I got this solution out od Microsofts website and I guess if they think its ok Its good for me.
Bert
___________________________________________
-
Apr 8th, 2007, 03:33 AM
#12
Re: [RESOLVED] [2005] Gridview and link button
The reasons I'm against code like:
<%# Eval("MyId", "MyId2" "showdetails.aspx?MyId={0}?????????"') %>
inserted into the page's source are:
1) Mixing of UI logic with UI elements. Always keep them separate.
2) Not scalable. Becomes more difficult to debug later. If you handle this in the DataBound events, you have more control over it and it's easier to debug later, especially when a new programmer comes in and sees this wonderful throwback to ASP Classic style of coding.
3) This code is executed after the object for the page is created and executed. That means there's two runs over for the same object and its methods. Inefficient.
4) This may be on Microsoft's website, but Microsoft also created ActiveX and we thought it was a good idea. Just because a lot of people use it doesn't make it right. It makes a lot of people wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|