Show friends name and image in gridview according his Userid in C#


Ranjana Acharya


To whomsoever it may be concerned,

I am using Microsoft Visual Studio 2005, I want to ask you a question on C#
I am doing a project, I have a friends.aspx page in which I have taken three
textboxes and one file upload control , four labels viz. Userid, friendname,
friendimage, FriendUserid for inserting data in data table called friends.

My data table looks like this:

Columnname Datatype Allows Null
Primary key Fid int not null

Userid int not

Friendname varchar(50) allows null

Friendimage image allows null

FriendUserid int not null

I insert data through textboxes using insert button and I have a
showimage.ashx page for displaying image in gridview according to

I have another page Home.aspx in which I have taken 1 gridview the source is
as follows

<asp:GridView ID="GridView2" runat="server" >
<asp:BoundField DataField="Userid"
HeaderText="Userid" />
<asp:BoundField DataField="friendname"
HeaderText="friendname" />
<asp:TemplateField HeaderText="friendimage">
<asp:Image ID="Image2" runat="server"
ImageUrl='<%# "showimage.ashx?fuserid="+ Eval("fuserid") %>' />

I have written a show method for displaying data in a gridview.But my
problem is am not able to show name and image of a friend according to
Userid. The one who logs in should able to see only his friends the one who
has not inserted any friends should not be able to see the gridview. I tried
using select statement like this

private void show(int Userid)

SqlConnection cn = new
cmd = new SqlCommand("Select * from friends where
[email protected]", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "friends");
GridView2.DataSource = ds.Tables[0];
catch (Exception ex)

Connection string is as follows:
<add name="con" connectionString="Data
Source=toshiba-user\sqlexpress;Initial Catalog=Blog;Integrated

But gridview is not seen. Can I show Friends data according Userid in the
same gridview but separately like I said before the person who logs in should
be able to see only his friends names and images and the one who has not
made any friends should not be able to see the gridview. Can U please Help me.




Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question