473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Need Suggestion

Greetings,

My app displays users in a GridView control. I'd like to have the name field
shown in each row of this control a link that displays another page with
information about that user.

But I'm not sure how to approach this. How would I tell the target page
which user to display? I'd prefer not to pass the user's ID on the URL, and
I don't know when I'd get a chance to set a Session variable.

I know I can add a template with a link but, if I set an event handler for
that link, how does it know which row was selected?

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Dec 31 '07 #1
9 1391
One way is to do Server.Transfer to the user info page on server side.

The link on the grid will fire just a postback, perhaps a RowCommand event,
the server will find what row fired the event, get the user id from the row,
put it in a session variable and transfer to the info page.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
Greetings,

My app displays users in a GridView control. I'd like to have the name
field shown in each row of this control a link that displays another page
with information about that user.

But I'm not sure how to approach this. How would I tell the target page
which user to display? I'd prefer not to pass the user's ID on the URL,
and I don't know when I'd get a chance to set a Session variable.

I know I can add a template with a link but, if I set an event handler for
that link, how does it know which row was selected?

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jan 1 '08 #2
I've got a couple of ways to bring up another page. But, again, my issue is
providing the ID of the row the link was on.

So I couldn't quite follow your suggestion. Are you talking about built-in
row buttons, or something added via a template, or something else entirely?

That'd be a big help if you could clarify.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ev**************@TK2MSFTNGP04.phx.gbl...
One way is to do Server.Transfer to the user info page on server side.

The link on the grid will fire just a postback, perhaps a RowCommand
event, the server will find what row fired the event, get the user id from
the row, put it in a session variable and transfer to the info page.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
>Greetings,

My app displays users in a GridView control. I'd like to have the name
field shown in each row of this control a link that displays another page
with information about that user.

But I'm not sure how to approach this. How would I tell the target page
which user to display? I'd prefer not to pass the user's ID on the URL,
and I don't know when I'd get a chance to set a Session variable.

I know I can add a template with a link but, if I set an event handler
for that link, how does it know which row was selected?

Thanks for any tips.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jan 1 '08 #3
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:ev*************@TK2MSFTNGP03.phx.gbl...
So I couldn't quite follow your suggestion. Are you talking about built-in
row buttons, or something added via a template, or something else
entirely?
http://msdn2.microsoft.com/en-us/lib...lectedrow.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 1 '08 #4
Am I completely up in the night here, or is that "selected row" business
restricted to gridviews that have a select button?

I want a link for each row (preferrably a hyperlink in actual data) to
direct the user to another page, and to somehow tell that page which row the
link was clicked on. There would be no separate step of selecting a row.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:Od**************@TK2MSFTNGP03.phx.gbl...
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:ev*************@TK2MSFTNGP03.phx.gbl...
>So I couldn't quite follow your suggestion. Are you talking about
built-in row buttons, or something added via a template, or something
else entirely?

http://msdn2.microsoft.com/en-us/lib...lectedrow.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Jan 2 '08 #5
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:Oi**************@TK2MSFTNGP04.phx.gbl...
is that "selected row" business restricted to gridviews that have a select
button?
No.
I want a link for each row (preferrably a hyperlink in actual data) to
direct the user to another page, and to somehow tell that page which row
the link was clicked on. There would be no separate step of selecting a
row.
There are several ways you could do this...

Since you don't fancy the SelectedRow method, why not create a
TemplateColumn and add a LinkButton to it...? An asp:LinkButton is a button
control which looks like a hyperlink. This means that you can set its
CommandArgument value during the RowBinding of the GridView which you can
use to set a Session variable when the hyperlink is clicked, and then do a
Response.Redirect to the other page:
http://msdn2.microsoft.com/en-us/lib...dargument.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 2 '08 #6
Mark,
>is that "selected row" business restricted to gridviews that have a
select button?

No.
I don't understand how can there be a selected row if a grid has no means to
select one?
Since you don't fancy the SelectedRow method, why not create a
Given my lack of knowledge on it, I have nothing against the SelectedRow
method. It's just that I'm not seeing how that would produce the effect that
I want.
TemplateColumn and add a LinkButton to it...? An asp:LinkButton is a
button control which looks like a hyperlink. This means that you can set
its CommandArgument value during the RowBinding of the GridView which you
can use to set a Session variable when the hyperlink is clicked, and then
do a Response.Redirect to the other page:
I followed this right up to the point where I set the CommandArgument value
during the RowBinding of the GridView. I see the GridView has no RowBinding
event. There is a RowDataBound event. I can modify the handler like this:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Text = "What?";
}

I'm not clear on A) how I would access the LinkButton in this cell, B) how I
would respond to the link being clicked, and C) how I would know which row
the link was clicked on in my click handler.

Any chance you could fill this out a bit more for me?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jan 2 '08 #7
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>>is that "selected row" business restricted to gridviews that have a
select button?

No.

I don't understand how can there be a selected row if a grid has no means
to select one?
http://www.google.co.uk/search?sourc...EventReference
I'm not clear on A) how I would access the LinkButton in this cell,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
((LinkButton)e.Row.Cells[0].FindControl("MyLinkButton")).CommandArgument
= "<something>";
}
B) how I would respond to the link being clicked,
By specifying a Command event for the LinkButton in the TemplateColumn, same
way that you would respond to an <asp:Buttonbeing clicked...
and C) how I would know which row the link was clicked on in my click
handler.
You wouldn't need to now, because you've included the data you need in the
LinkButton's CommandArgument property...

http://www.thescripts.com/forum/thread554224.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 2 '08 #8
Mark,

I seem to be having trouble with this.
>>>is that "selected row" business restricted to gridviews that have a
select button?

No.

I don't understand how can there be a selected row if a grid has no means
to select one?

http://www.google.co.uk/search?sourc...EventReference
These articles still seem to be talking about making a row selectable.
That's not what I need.
>I'm not clear on A) how I would access the LinkButton in this cell,

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
{

((LinkButton)e.Row.Cells[0].FindControl("MyLinkButton")).CommandArgument =
"<something>";
}
>B) how I would respond to the link being clicked,

By specifying a Command event for the LinkButton in the TemplateColumn,
same way that you would respond to an <asp:Buttonbeing clicked...
>and C) how I would know which row the link was clicked on in my click
handler.

You wouldn't need to now, because you've included the data you need in the
LinkButton's CommandArgument property...

http://www.thescripts.com/forum/thread554224.html
Ack, okay, I think I finally wrapped my mind around this. I think I
incorporated some of what you were saying but kind of got the core from some
of the articles.

My GridView column looks like this:

<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="lnkName" runat="server" Text='<%# Eval("Name") %>'
CommandName="ViewTrainer" CommandArgument='<%# Eval("UserId") %>'
onclick="lnkName_Click">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

And then I can respond in either of two ways:

protected void lnkName_Click(object sender, EventArgs e)
{
Session["ID"] = ((LinkButton)sender).CommandArgument;
Response.Redirect("Trainer.aspx");
}

Or

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs
e)
{
if (e.CommandName == "ViewTrainer")
{
Session["ID"] = (string)e.CommandArgument;
Response.Redirect("Trainer.aspx");
}
}

The first version looks a little cleaner--I may go with that.

Thanks for your help.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jan 3 '08 #9
On Mon, 31 Dec 2007 16:08:24 -0700, "Jonathan Wood"
<jw***@softcircuits.comwrote:
>Greetings,

My app displays users in a GridView control. I'd like to have the name field
shown in each row of this control a link that displays another page with
information about that user.

But I'm not sure how to approach this. How would I tell the target page
which user to display? I'd prefer not to pass the user's ID on the URL, and
I don't know when I'd get a chance to set a Session variable.

I know I can add a template with a link but, if I set an event handler for
that link, how does it know which row was selected?

Thanks for any tips.
Look at cross-page posting.

regards
A.G.
Jan 3 '08 #10

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

Similar topics

11
by: Jack | last post by:
I have a asp form where among others there are few text boxes and one check box. The checkbox is to indicate whether the entry is final. The checkbox is attahced to a field in table of type...
5
by: John | last post by:
Hi: I'd like to implement a simple map, which is a 2-D plane with many points, e.g., 100. The points are not evenly distributed, i.e., some points may have two neighbor points; some may have 5...
9
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
5
by: news | last post by:
I have a new situation I'm facing and could use a suggestion or two, as I don't seem to be able to think in the abstract very well. We have a local server which holds all of our image files. We...
106
by: xtra | last post by:
Hi Folk I have about 1000 procedures in my project. Many, many of them are along the lines of function myfuntion () as boolean on error goto er '- Dim Dbs as dao.database Dim Rst as...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
13
by: vincent | last post by:
I made the suggestion "Need built in obfuscation support in C# compiler" to Microsoft. Anyone here agree with me? If yes, please cast your vote on this suggestion to raise its priority.
1
by: msnews.microsoft.com | last post by:
Hi Every one, I need your suggestion. I want to implement a scenario. The Scenario is "I build a web site. I deploy it to web server. Now I want and auto email alter. The responsibility of...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.