R
Ranjana Acharya
Hello!!!
To whomsoever it may be concerned,
I am using Microsoft Visual Studio 2005, I want to ask you a question on C#
ASP.net
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
null
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
FriendUserid
I have another page Home.aspx in which I have taken 1 gridview the source is
as follows
<asp:GridView ID="GridView2" runat="server" >
<Columns>
<asp:BoundField DataField="Userid"
HeaderText="Userid" />
<asp:BoundField DataField="friendname"
HeaderText="friendname" />
<asp:TemplateField HeaderText="friendimage">
<ItemTemplate>
<asp:Image ID="Image2" runat="server"
ImageUrl='<%# "showimage.ashx?fuserid="+ Eval("fuserid") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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)
{
try
{
SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
cmd = new SqlCommand("Select * from friends where
Userid=@Userid", cn);
cmd.Parameters.AddWithValue("@Userid",Userid);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "friends");
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Connection string is as follows:
<configuration>
<appSettings/>
<connectionStrings>
<add name="con" connectionString="Data
Source=toshiba-user\sqlexpress;Initial Catalog=Blog;Integrated
Security=True"/>
</connectionStrings>
<system.web>
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.
Regards,
Ranjana.
To whomsoever it may be concerned,
I am using Microsoft Visual Studio 2005, I want to ask you a question on C#
ASP.net
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
null
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
FriendUserid
I have another page Home.aspx in which I have taken 1 gridview the source is
as follows
<asp:GridView ID="GridView2" runat="server" >
<Columns>
<asp:BoundField DataField="Userid"
HeaderText="Userid" />
<asp:BoundField DataField="friendname"
HeaderText="friendname" />
<asp:TemplateField HeaderText="friendimage">
<ItemTemplate>
<asp:Image ID="Image2" runat="server"
ImageUrl='<%# "showimage.ashx?fuserid="+ Eval("fuserid") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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)
{
try
{
SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
cmd = new SqlCommand("Select * from friends where
Userid=@Userid", cn);
cmd.Parameters.AddWithValue("@Userid",Userid);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "friends");
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Connection string is as follows:
<configuration>
<appSettings/>
<connectionStrings>
<add name="con" connectionString="Data
Source=toshiba-user\sqlexpress;Initial Catalog=Blog;Integrated
Security=True"/>
</connectionStrings>
<system.web>
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.
Regards,
Ranjana.