Reputation: 436
I have a homepage with a friend list and other page 'chatbox'. i have one dynamic list getting generated using Gridview. That list is the list of friends and when user clicks on the name of the friends, an Id of that friend's name and the id of the user( that is in session) must be passed to another page('chatbox.aspx').
Code:
HomePage1.aspx(partial code)
<asp:GridView GridLines="None" ID="GridView1" class="active bounceInDown" onClientClick="#chat-message"
runat="server" AutoGenerateColumns="false" CellPadding="4" ForeColor="#333333" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:TemplateField HeaderText="Friends">
<ItemTemplate>
<a href='<%# "chatbox.aspx?User=" + Eval("Ownerid") + "?Friend=" + Eval("Friendid") %>'>
<%# Eval("FName") %>
</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
On clicking to the name i can get the two values: userid and friend id in the url of the next page('chatbox.aspx') , i just want to know how do i use them for further coding in new page('chatbox.apsx').
Upvotes: 0
Views: 70
Reputation: 436
Solution:
int oid = new int();
int pid = new int();
if (Request.QueryString["User"] != null && Request.QueryString["Friend"] != null)
{
oid = Convert.ToInt32(Request.QueryString["User"]);
OwnerName.Visible = true;
UserTable q = Class1.selectByID(oid);
OwnerName.Text = q.LName;
pid = Convert.ToInt32(Request.QueryString["Friend"]);
FriendName.Visible = true;
UserTable a = Class1.selectByID(pid);
FriendName.Text = a.LName;
}
Upvotes: 1
Reputation: 35514
You would normally do something like this on the page that receives the url with the querystring.
//declare a variable to on the new page for the passed id
int Ownerid = new int();
//check if the querystring exists
if (Request.QueryString["User"] != null)
{
//wrap the conversion in a try-catch blok because in a querystring a user can change the value
try
{
//convert the querystring to a usable value
Ownerid = Convert.ToInt32(Request.QueryString["User"]);
}
catch
{
}
}
Upvotes: 1
Reputation: 854
Additional parameters in a query string should be seperated by & so
<a href='<%# "chatbox.aspx?User=" + Eval("Ownerid") + "&Friend=" + Eval("Friendid") %>'>
In your cs page you should be requesting User and Friend
var user = Request.QueryString["User"];
var friend = Request.QueryString["Friend"];
Upvotes: 0