遇到asp:gridview有困难

时间:2012-02-15 10:34:00

标签: c# gridview .net-3.5 asp.net-3.5 querystringparameter

我似乎遇到了asp:querystringparameterasp:gridview的问题。到目前为止,我有以下内容,它只返回“无数据可用”:

<%@ 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>

1 个答案:

答案 0 :(得分:1)

您也可以在代码后面动态绑定gridview。如果您的查询返回任何数据,请尝试调试。是否有使用SqlDataSource的具体原因?