I seem to be having difficulty with asp:querystringparameter and asp:gridview. I have the following so far and it just returns "no data available":

<%@ Page Language="C#" %>

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

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        String strGroup = Request.QueryString["group"];

        switch(strGroup){
            case "Clients":
                ClientSource.SelectCommand = @"select client_code, 
                client_name from table1 where client_name = @phrase";
                break;
            case "Addresses":
                /*different query here*/
                break;
            case "Matters":
                /*different query here*/
                break;
            default:
                break;
        }

    }
</script>

<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="ClientGridView" 
            datasourceid="ClientSource" 
            emptydatatext="No data available." 
            runat="server">

        </asp:gridview>

        <asp:SqlDataSource id="ClientSource"
            runat="server"
            ConnectionString="connection string goes here">
            <SelectParameters>
                <asp:QueryStringParameter Type="String" Name="phrase" QueryStringField="phrase" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
有帮助吗?

解决方案

you can bind gridview dynamically in code behind also. Try to debug if your query is returning any data. Is there any specific reason to use SqlDataSource?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top