Asp.net 一个带有3个搜索选项的dataGrid

Asp.net 一个带有3个搜索选项的dataGrid,asp.net,Asp.net,我的场景是:我有一个5-6列的dataGrid。我有3个过滤器,它们使用codeBehind中的3个SQL查询方法:SearchByName()、SearchByValue()、SearchByDate()。我有第四个方法show DefaultShow(),它显示不带任何过滤器的所有数据。 基本上我希望在加载页面时加载DefaultShow()方法,然后用户可以使用RadioButtonList选择搜索选项 DefaultShow()代码是: public void DefaultShow(

我的场景是:我有一个5-6列的dataGrid。我有3个过滤器,它们使用codeBehind中的3个SQL查询方法:SearchByName()、SearchByValue()、SearchByDate()。我有第四个方法show DefaultShow(),它显示不带任何过滤器的所有数据。 基本上我希望在加载页面时加载DefaultShow()方法,然后用户可以使用RadioButtonList选择搜索选项

DefaultShow()代码是:

 public void DefaultShow()
        {
            string connectionString = cs.getConnection();
            string query = "select Id ,name,value,Description,DateCreate from AllCostView where  IdUser = '" + cui.getCurrentId() + "'";
            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                myConnection.Open();

                SqlCommand command = new SqlCommand(query, myConnection);

                SqlDataAdapter mySqlAdapter = new SqlDataAdapter(command);
                using (DataTable myDataTable = new DataTable())
                {
                    mySqlAdapter.Fill(myDataTable);
                    GridViewCost.DataSource = myDataTable;
                    GridViewCost.DataBind();
                }

            }
        }



protected void Page_Load(object sender, EventArgs e)
        {

                DefaultShow();

        }
但这不管用我错过了什么?

我的gridViewCode如下所示:

<div class ="gridView">
    <asp:GridView ID="GridViewCost" runat="server" AutoGenerateColumns="False" CaptionAlign="Top" 
        ShowFooter="True" ShowHeaderWhenEmpty="True" Font-Overline="False" 
        Font-Strikeout="False" Font-Underline="False" 
         AllowPaging="true"
        PageSize="5"
        CssClass="mGrid"  
    PagerStyle-CssClass="pgr"  
    AlternatingRowStyle-CssClass="alt" OnPageIndexChanging="GridViewCost_PageIndexChanging" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" >
        <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
        <Columns>

            <asp:BoundField DataField="Id" HeaderText="Номер" />
            <asp:TemplateField HeaderText="Име">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                </ItemTemplate>
                <ControlStyle Width="100px" />
            </asp:TemplateField>
            <asp:BoundField DataField="Value" HeaderText="Стойност" />
            <asp:BoundField DataField="Description" HeaderText="Описание" />
            <asp:BoundField DataField="DateCreate" HeaderText="Дата"   />

        </Columns>
        <AlternatingRowStyle />
        <HeaderStyle  HorizontalAlign="Right"/>
        <PagerStyle />
        <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" />

    </asp:GridView>


如果需要,我会发布更多的代码。谢谢。

您有错误吗?如果在SQLServerManagementStudio中运行,查询是否返回数据?