assign queryString value to session

Posted by Rickeybglr under ASP.NET on 9/7/2012 | Points: 10 | Views : 2023 | Status : [Member] | Replies : 6
Hi All
On click on gridview row, i have to pass gridview row primary key in queryString which redirect to appropiate user home page.
i have only one home page. proper content of home page loaded on the basis of session value which holds primary key as userName.
so in short i need to pass primary key as a querystring from search page to homepage.

Session["userName"] = Session["userName"].ToString();




Responses

Posted by: Wadhwanisanju on: 9/7/2012 [Member] Starter | Points: 25

Up
0
Down
Hello,

i think you shoule follow this route which is easy and understandable.

here i am giving a code of gridview having linkbutton as Edit and Delete having command argument as their respec ids in database.

<asp:GridView ID="gvGroup" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"
EmptyDataText="No Rows" onrowdatabound="gvGroup_RowDataBound">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandArgument='<%# Eval("GroupID") %>' OnCommand="lnk_Edit" CausesValidation="False">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btndelete" runat="server" CausesValidation="False" CommandArgument='<%# Eval("GroupID") %>' OnCommand="lnk_Delete" OnClick="OnConfirm" OnClientClick="Confirm()" >Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



You will get the Groupid in code behind like the below code :

protected void lnk_Edit(object sender, CommandEventArgs e)

{
btnSave.Enabled = true;
Session["GroupID"] = e.CommandArgument.ToString();
}



This is how you will get each unique id per row in gridview.

hope this helps.

If you find this the answer please mark as answer.

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 9/10/2012 [Member] Starter | Points: 25

Up
0
Down
Session["userName"] = txtUserName.Text;  


instead of

Session["userName"] = Session["userName"].ToString();


John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/28/2012 [Member] Starter | Points: 25

Up
0
Down
Good one sanju

Thanks & Regards
Hari

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/28/2012 [Member] Starter | Points: 25

Up
0
Down
Good one sanju

Thanks & Regards
Hari

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/28/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this

int EmployeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
session["userName"]=EmployeeID;

then redirect receive them.

Mark as Answer if its helpful to you

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/28/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.


Mark as Answer if its helpful to you

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response