Need Suggestion
am 01.01.2008 00:08:24 von Jonathan Wood
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
Re: Need Suggestion
am 01.01.2008 11:37:51 von Eliyahu Goldin
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" wrote in message
news:O59hPIATIHA.5288@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
>
Re: Need Suggestion
am 01.01.2008 20:05:02 von Jonathan Wood
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" wrote in
message news:ev7m4JGTIHA.5288@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" wrote in message
> news:O59hPIATIHA.5288@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
>>
>
>
Re: Need Suggestion
am 01.01.2008 20:27:39 von mark
"Jonathan Wood" wrote in message
news:evny4kKTIHA.280@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/library/system.web.ui.webco ntrols.gridview.selectedrow.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Need Suggestion
am 02.01.2008 01:46:31 von Jonathan Wood
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]" wrote in message
news:OdAgSxKTIHA.1208@TK2MSFTNGP03.phx.gbl...
> "Jonathan Wood" wrote in message
> news:evny4kKTIHA.280@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/library/system.web.ui.webco ntrols.gridview.selectedrow.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Re: Need Suggestion
am 02.01.2008 02:44:59 von mark
"Jonathan Wood" wrote in message
news:Oi$TtjNTIHA.3532@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/library/system.web.ui.webco ntrols.linkbutton.commandargument.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Need Suggestion
am 02.01.2008 04:58:48 von Jonathan Wood
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
Re: Need Suggestion
am 02.01.2008 15:13:12 von mark
"Jonathan Wood" wrote in message
news:%23dR5JPPTIHA.748@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?sourceid=navclient&aq=t&hl=en -GB&ie=UTF-8&rlz=1T4GZEZ_en-GBGB252GB252&q=GridView+ClientSc ript%2eGetPostBackEventReference
> 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")).Com mandArgument
= "";
}
> 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 being 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
Re: Need Suggestion
am 03.01.2008 04:33:01 von Jonathan Wood
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?sourceid=navclient&aq=t&hl=en -GB&ie=UTF-8&rlz=1T4GZEZ_en-GBGB252GB252&q=GridView+ClientSc ript%2eGetPostBackEventReference
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")).Com mandArgument =
> "";
> }
>
>> 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 being 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:
CommandName="ViewTrainer" CommandArgument='<%# Eval("UserId") %>'
onclick="lnkName_Click">LinkButton
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
Re: Need Suggestion
am 03.01.2008 08:00:01 von Registered User
On Mon, 31 Dec 2007 16:08:24 -0700, "Jonathan Wood"
wrote:
>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.