Passing values to sql datasource

J

John

Hi

I am trying to pass the asp.net membership username to the sqldatasource of
a gridview as below;

<asp:SqlDataSource ID="EventsSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnStr %>" SelectCommand="SELECT
* FROM [MyTable] WHERE [Username] =
'<%Me.User.Identity.Name%>'"></asp:SqlDataSource>

It is not working. How can I do it correctly?

Thanks

Regards
 
M

Munna

Hi

I am trying to pass the asp.net membership username to the sqldatasource of
a gridview as below;

<asp:SqlDataSource ID="EventsSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnStr %>" SelectCommand="SELECT
* FROM [MyTable] WHERE [Username] =
'<%Me.User.Identity.Name%>'"></asp:SqlDataSource>

It is not working. How can I do it correctly?

Thanks

Regards

Hi i have tried your same code and worked okay make be you are meesing
some thing....

here is the code i tried..

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [testtable] where id = '<%
Page.User.Identity.Name %>' "></asp:SqlDataSource>

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
M

Munna

Hi its me again...

I found another way to make things work i have tested it and works
pretty fine..
in markup i actually didn't put any select command.

instead i left the select command blank

i assigned the select command in code behind file in page load
event ...

SqlDataSource1.SelectCommand = "SELECT * FROM [testtable] where id
like '%" + Page.User.Identity.Name + "%'";

and

data source mark up is

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:ConnectionString %>" ></
asp:SqlDataSource>


Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top