
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 2.19 KB | hits: 13 | expires: Never
asp.net query string databind [closed]
http://localhost:61279/clubpage.aspx?CategoryID=1
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Youth clubs</h2>
<p>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
EnableViewState="False">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<%-- <%--<%-- You can use an anchor element... --%>
<%-- <li><a href='youthclubpage.aspx?CategoryID=<%# Eval("YouthClubID") %>'><%# Eval("youthclubname") %></a> - <%# Eval("description") %></li> --%>
<%-- Or a HyperLink Web control...---%>
<li><asp:HyperLink runat="server" Text='<%# Eval("youthclubname") %>' NavigateUrl='<%# "youthclubpage.aspx?CategoryID=" + Eval("YouthClubID") %>'></asp:HyperLink>
- <%# Eval("Description") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:joanton7865org7272_youthpodcastConnectionString %>"
SelectCommand="SELECT [youthclubname], [description], [YouthClubID] FROM [youthclublist]">
</asp:SqlDataSource>
</p>
</asp:Content>
int categoryId = 0;
if(int.TryParse(Request.Params["CategoryID"]), out categoryId))
{
// query data with categoryID
}
else
{
// no category id
Response.Redirect("Default.aspx");
}
int CatagoryID = Request["CatagoryID"];
string myQuery = "Select Fields from table where [Filtered column] = " + CatagoryID;
int categoryId = 0;
if(Request["CategoryID"]!=null)
{
categoryID=Convert.ToInt32(Request["CategoryID"]);
SqlConnection ConnObject = new SqlConnection("ConnString of your SQL Provider");
SqlCommand cmd = new SqlCommand("select some thing from your table where category_ID=@catID",ConnObject);
cmd.Parameters.AddWithValue("@catID", categoryId);
SqlDatareadr dr= cmd.ExecuteReader();
while(dr.read())
{
// use the returned values from DB
}
}
else
{
//category not exist
}