Populating SqlDatasource using querystring parameter in aspx page

By Mash B

Given QueryString parameter in URL populate the sqlDatasource and bind to any binding control like gridview,repeater control etc in aspx page.


For example below is the querystring  parameter

http://xyz.com/abcd.aspx?ID=210

Below is the code in abcd.aspx which binds data to gridview with given querystring parameter

<asp:SqlDataSource  
  
ID="SqlDataSource1"  
  
runat="server"  
  
ConnectionString="<%$ ConnectionStrings:SampleDBConnectionString %>"  
  
DataSourceMode="DataReader"  
  
SelectCommand="SELECT FName, LName FROM Person WHERE ID=@PersonID"  
  >
  
  <SelectParameters>  
<asp:QueryStringParameter Name="PersonID" QueryStringField="ID" />  
  </SelectParameters>  
</asp:SqlDataSource>  
  
<asp:Gridview  
  
ID="Gridview1"  
  
runat="server"  
  
DataSourceID="SqlDataSource1"  
>
  
     </asp:Gridview>

Populating SqlDatasource using querystring parameter in aspx page  (2667 Views)