一个带有3个搜索选项的dataGrid

时间:2013-04-24 08:21:12

标签: asp.net

我的方案是:我有一个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>

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

0 个答案:

没有答案