GridView控件提供管理审核过滤问题
//GridView设置显示信息
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Font-Size="9pt" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="4" ForeColor="#333333" GridLines="None">
                <Columns>
                    <asp:BoundField DataField="id" HeaderText="信息ID" />
                    <asp:BoundField DataField="name" HeaderText="信息主题" />
                    <asp:BoundField DataField="type" HeaderText="信息分类" />
                    <asp:BoundField DataField="userName" HeaderText="发布人" />
                    <asp:BoundField DataField="lineMan" HeaderText="联系人" />
                    <asp:BoundField DataField="term" HeaderText="有效期" DataFormatString="{0:d}" />
                    <asp:BoundField DataField="check" HeaderText="审核" />
                    <asp:CommandField HeaderText="通过/取消" SelectText="通过/取消" ShowSelectButton="True" />
                </Columns>
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Right" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
//绑定数据信息显示经过数据库审核的过滤信息
 SqlConnection sqlcon;
    string strCon = ConfigurationManager.AppSettings["conStr"];
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.GV_DataBind();
        }
       
    }
    public void  GV_DataBind()
    {
        string sqlstr = "select * from tb_inf ";
        sqlcon = new SqlConnection(strCon);
        SqlDataAdapter da = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet ds = new DataSet();
        sqlcon.Open();
        da.Fill(ds);
        sqlcon.Close();
        this.GridView1.DataSource = ds;
        this.GridView1.DataKeyNames = new string[] { "id" };
        this.GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[6].Text == "False")
            {                e.Row.Cells[6].Text = "<font color=red>已通过</font>";
            }
            else
            {
                e.Row.Cells[6].Text = "未通过";
            }
        }
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        sqlcon = new SqlConnection(strCon);
        SqlCommand com = new SqlCommand("select [check] from tb_inf where id='" + id + "'", sqlcon);
        sqlcon.Open();
        string count = Convert.ToString(com.ExecuteScalar());
        if (count == "False")
        {
            count = "1";
        }
        else
        {
            count = "0";
        }
        com.CommandText = "update tb_inf set [check]=" + count + " where id=" + id;
        com.ExecuteNonQuery();
        sqlcon.Close();
        this.GV_DataBind();  
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       this.GridView1.PageIndex= e.NewPageIndex;
       this.GV_DataBind();
    }

解决方案 »

  1.   

    你可以使用<HeaderTemplate>放一个下拉控件,直接填入数据
    或者在绑定事件里面进行数据动态绑定也可以
      

  2.   

    在标题列那追加dropdownlist控制。然后dpx选择事件里面筛选
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
           DataView dw = dt().DefaultView;       
           //这里假设我们筛选字段为ID
           dw.RowFilter = " ID='" + DropDownList1.SelectedItem.Text + "'";
           GridView1.DataSource = dw;
           GridView1.DataBind();
    }