Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 2.19 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. asp.net query string databind [closed]
  2. http://localhost:61279/clubpage.aspx?CategoryID=1
  3.        
  4. </asp:Content>
  5. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  6.     <h2>
  7.         Youth clubs</h2>
  8.     <p>
  9.         <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
  10.         EnableViewState="False">
  11.             <HeaderTemplate>
  12.                 <ul>
  13.             </HeaderTemplate>
  14.  
  15.             <ItemTemplate>
  16.                <%-- <%--<%-- You can use an anchor element... --%>
  17.             <%--    <li><a href='youthclubpage.aspx?CategoryID=<%# Eval("YouthClubID") %>'><%# Eval("youthclubname") %></a> - <%# Eval("description") %></li> --%>                
  18.  
  19.                  <%-- Or a HyperLink Web control...---%>
  20.                 <li><asp:HyperLink runat="server" Text='<%# Eval("youthclubname") %>' NavigateUrl='<%# "youthclubpage.aspx?CategoryID=" + Eval("YouthClubID") %>'></asp:HyperLink>
  21.                   - <%# Eval("Description") %></li>
  22.  
  23.             </ItemTemplate>
  24.  
  25.             <FooterTemplate>
  26.                 </ul>
  27.             </FooterTemplate>
  28.         </asp:Repeater>
  29.         <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  30.         ConnectionString="<%$ ConnectionStrings:joanton7865org7272_youthpodcastConnectionString %>"
  31.  
  32.         SelectCommand="SELECT [youthclubname], [description], [YouthClubID] FROM [youthclublist]">
  33.     </asp:SqlDataSource>
  34.     </p>
  35.  
  36.     </asp:Content>
  37.        
  38. int categoryId = 0;
  39.  
  40. if(int.TryParse(Request.Params["CategoryID"]), out categoryId))
  41. {
  42.   // query data with categoryID
  43. }
  44. else
  45. {
  46.   // no category id
  47.   Response.Redirect("Default.aspx");
  48. }
  49.        
  50. int CatagoryID = Request["CatagoryID"];
  51.  
  52. string myQuery = "Select Fields from table where [Filtered column] = " + CatagoryID;
  53.        
  54. int categoryId = 0;
  55.  
  56. if(Request["CategoryID"]!=null)
  57. {
  58. categoryID=Convert.ToInt32(Request["CategoryID"]);
  59. SqlConnection ConnObject = new SqlConnection("ConnString of your SQL Provider");
  60. SqlCommand cmd = new SqlCommand("select some thing from your table where category_ID=@catID",ConnObject);
  61. cmd.Parameters.AddWithValue("@catID", categoryId);
  62. SqlDatareadr dr= cmd.ExecuteReader();
  63. while(dr.read())
  64. {
  65. // use the returned values from DB
  66. }
  67. }
  68. else
  69. {
  70.  
  71. //category not exist
  72. }