Passing values to sql datasource

  • Thread starter Thread starter John
  • Start date Start date
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
 
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
 
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
 
Back
Top