What i want to do is:
1. Login
2. show an image from a SQL database, based on that login.
I have the image path stored in the database, and i can easily get itto display on the screen, but it doesnt show the correct image for thelogin, it shows them all. (all images based on that column).
I know i have to put a WHERE at the end of my SELECT statement, but everything i have tried doesnt work.
When i do the query builder, and i put in the value, it shows exactly what i want, based on the login's username.
I know i am close, i just can't finish it.
Please help.
ThanksLet us see your problematic code so that we can make suggestions.|||I made a Gridview and a DetailsView, to see if one of them wont do whati want. I guess i dont totally know the ins and outs of them yet.
<asp:SqlDataSource ID="SqlDataSource2" runat="server"ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString%>" SelectCommand="SELECT * FROM [aspnet_Users]">
</asp:SqlDataSource
<asp:DetailsView BorderStyle="None" ID="DetailsView1"DataSourceID="SqlDataSource2" runat="server"AutoGenerateRows="False">
<Fields>
<asp:ImageField DataImageUrlField="PersonImageType" DataImageUrlFormatString="~/images/{0}"></asp:ImageField>
</Fields>
</asp:DetailsView>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" AllowPaging="True">
<Columns>
<asp:ImageField DataImageUrlField="PersonImageType" DataImageUrlFormatString="~/images/{0}">
</asp:ImageField>
</Columns>
</asp:GridView
I know i am missing something, i am just stressed out of my mind now.
Thanks|||
Add this to your page_load (There are "Better" places to put this, but it's easy and will get you started)
Session("Username")=membership.getuser.username
Then change your SqlDatasource to:
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" SelectCommand="SELECT * FROM [aspnet_Users] WHERE Username=@.Username">
<SelectParameters>
<asp:SessionParameterName="Username"SessionField="Username"Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
|||Oh very nice!
I knew i was close. I did have to the <selectparameters> in there at one time, i just needed the session part.
Thanks SO much, i got me in the right direction, to be able to do whati needed. Now that i look at it, it makes alot of sense why minewasn't working.
Thanks!
No comments:
Post a Comment