2

i try this example but not working.

<%string id = Request.QueryString["id"]; %>// get value and set in one variable
<%=id%>// display successfully variable's value
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
SelectCommand="SELECT [id], [name], [image], [old_price], [new_price] FROM [product] where [id]= "'<%=id%>'"" ></asp:SqlDataSource>

a problem in SelectCommand how to set variable in query i try like <%=id%>

Saan
  • 178
  • 1
  • 11
  • 1
    a problem in SelectCommand how to set variable in query i try like <%=id%>. – Saan Jan 19 '15 at 14:00
  • 1
    I warmly suggest you NOT to mix the presentation layer of your app with the data layer. There are tons of reasons. Among them, security, logic decoupling, maintenance. Please, do not do that. For further details on the SelectCommand, please check [here](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.selectcommand%28v=vs.110%29.aspx). – Alberto De Caro Jan 19 '15 at 14:04
  • This link might help you ..http://stackoverflow.com/questions/3319358/changing-sqldatasource-selectcommand-at-runtime-breaks-pagination – Jay Jan 19 '15 at 14:08
  • 1
    i am not display a database in gridview. in normal html table. – Saan Jan 19 '15 at 14:11

1 Answers1

1

Use the codebehind, for example in the Selecting event:

<asp:SqlDataSource ID="SqlDataSource1" ... OnSelecting="Product_Selecting">

Codebehind:

protected void Product_Selecting(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Command.Parameters[0].Value = Request.QueryString["id"];
} 
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939