Solved

Gridview Hyperlink value. Need to pass to another page but not using QueryString.

Posted on 2008-06-13
5
7,191 Views
Last Modified: 2013-11-26
On btnSearch_Click event I bind the gridview. First column "Name" is the hyperlink and the second column "UserID" value I need to pass to another page but NOT using Request.QueryString.
Here is the visual of bind datagrid:
Full Name........................User ID....................Header title.................
Joe, Doe ........................123456...................other cell values ..........
Jane, Doe........................78910.....................other cell values..........

The grid might contain a single row or hundreds of rows.
Based on the code below I'm getting hyperlink href="nextpage.aspx?id=y&userid=12345" and so on. However, I need the following:
a. Hide the userid value so the user just sees "nextpage.aspx?id=y"
b. Pass userid value to the next page when user clicks on the link.

Should I use session variable,  hidden fields or what? But how? Example please.
<asp:gridview ID="gvGetUser" AutoGenerateColumns="false"..../>

 <columns>

<asp:hyperlinkfield DataTextField="Name" HeaderText="Full Name" ItemStyle-HorizontalAlign="left" ControlStyle-CssClass="lnk" 

 DataNavigateUrlFields="UserID" DataNavigateUrlFormatString="nextpage.aspx?id=y&userid={0}"  />

<asp:boundfield DataField="UserID" HeaderText="User ID" />

....

</columns>

</asp:gridview>

Open in new window

0
Comment
Question by:vbnetdev
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:ajitha75
ID: 21783794
When you say you want to hide the user id, do you mean the user should never be able to find out the user id value in second page.  if that is the case, you should not use hidden variable. you can go for session values.
or you should encrypt the url and decrypt it in the next page.
0
 
LVL 1

Author Comment

by:vbnetdev
ID: 21784548
Yes, the user should NOT see the user id when mouse over the link (1st page) along with when the next page loads. And if using session variable, how would I set an individual user id into session or encrypt the value if datagrid might contrain more then 1 row. The user would click only one (user id) at the time and I need an example how to set the value into session since I don't know which link the user clicks. This userid value I need to pass to the next page and run another stored procedure as a passed parameter.

Hope it's clear.
0
 
LVL 1

Author Comment

by:vbnetdev
ID: 21787225
Maybe i should set a button with CommandName="Select" first. That way I will know which row the user selected. Then when the row is selected, grab "UserID" value, set into session variable and redirect to the next page.

Anybody else? Surprised just 1 person responded.
0
 
LVL 14

Accepted Solution

by:
ajitha75 earned 250 total points
ID: 21787318
This is what you can do.

THe following will be html code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="true">
<Columns>  
<asp:TemplateField HeaderText="Navigate">
<ItemTemplate>
<asp:LinkButton id="lnkButton" OnCommand="lnkButton_Click" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"userid") %>' runat="server" Text="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
            </Columns>
        </asp:GridView>


and on the server side

    protected void lnkButton_Click(object sender, CommandEventArgs e)
    {
        Session["userid"] = e.CommandArgument;
        Server.Transfer("default2.aspx");

    }

Of course you will first have to do DataBind in the initial load to bind the datatable to gridview
0
 
LVL 1

Author Comment

by:vbnetdev
ID: 21796997
Thanks but it complained about (Containter.DataItem, "userid") under CommandArgument.

I decided to give a different approach.
User clicks search button to get the grid fill with hyperlink as one of the columns.

a. On button_Click event I create a hashtable, bind the grid and add hastable into Session variable.
b. Under _RowDataBound grid event I create a NewGuid, add NewGuid  as a key with "userid" value.
c. Then  programmatically create a hyperlink with .NavigateUrl set to "nextpage.aspx?guid=" + guid.toString
d. I keep UI hyperlink column just with DataTextField, HeaderText and  ControlStyle-CssClass
e. Nextpage.aspx page will read Session varialble and grabs assigned UserID value based on matched guid received through QueryString.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 36
how to read json value 2 29
Visual Studio 2015 Source Code Control 10 26
Reset asp.net login password 4 26
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now