0

I have the following which works fine:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_library_newsletter_Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">

    <div  style="font-family:Arial;">
        <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="false"
        emptydatatext="No data available." 
        allowpaging="true" 
        runat="server"
        ShowHeader="True"
        GridLines="None"
        CellPadding="10">

        <Columns>
            <asp:BoundField HeaderText="Date"
            DataField="date"
            dataformatstring="{0:dd-MM-yyyy}" />

            <asp:HyperLinkField HeaderText="Subject"
            DataTextField="subject"
            DataNavigateUrlFields="id"
            DataNavigateUrlFormatString="http://intranet/Default2.aspx?id={0}" />
        </Columns>

        <pagersettings mode="Numeric"
        position="Bottom"           
        pagebuttoncount="10"/>

            <HeaderStyle HorizontalAlign="Left" />


        </asp:gridview>

        <asp:sqldatasource id="CustomersSource"
        selectcommand="select id, subject, date from table order by id desc"
        connectionstring="connection string here" 
        runat="server"/>

    </div>
    </form>
</body>
</html>

However, I want to use a querystring value in the sql statement. How do I do that?

1 Answer 1

2

you need something like this

<asp:SqlDataSource ID="ID" runat="server" ConnectionString="connectionString"
    ProviderName="providerName"
    SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products] WHERE     ([CategoryID] = ?)">
    <SelectParameters>
        <asp:QueryStringParameter Type="Int32" 
            Name="CategoryID" 
            QueryStringField="CategoryID" />
    </SelectParameters>
</asp:SqlDataSource>

Read full post at https://web.archive.org/web/20211020150717/https://www.4guysfromrolla.com/articles/030106-1.aspx

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.