如何隐藏DropDownList筛选器中除All值之外的所有值的GridView中的第一列? [英] How to hide the first column in the GridView for all values in the DropDownList Filter except for the All value?

查看:61
本文介绍了如何隐藏DropDownList筛选器中除All值之外的所有值的GridView中的第一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Repeater控件内使用GridView来生成三个GridView,这些GridView具有3个相似的列,并且它们之间具有不同数量的不同列.一切正常,一切顺利.我只是面对一个筛选结果已解决的问题.
我有一个基于部门"名称的筛选器"作为下拉列表.该过滤器显示以下值:全部和从数据库中检索的部门名称.
当我基于这些除法之一过滤结果时,没有显示除法名称,而是以编程方式隐藏除法"列.现在,我希望过滤器的值为All时显示除数列,而不是All值时显示该列.那怎么办呢?

我的ASP.NET代码:

Hello everybody,

I am using a GridView inside a Repeater control to generate three GridViews with 3 similar columns and different number of different columns between them. Everything works fine and well. I am just facing one probelm with the filtered results.
I have a Filter as dropdownlist based on the Division name. This filter shows the following values: All and the division names which are retrieved from the database.
Instead of showing the divison name when I filtered the results based on the one of these divisions, I hide the Division column programmatically. Now, I want when the value of filter is All to show the Divison column when it is other than All value to show that column. So how to do that?

My ASP.NET code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
                                    SelectCommandType="StoredProcedure" SelectCommand="kbiReport"
                                    FilterExpression="[DivisionName] like ''{0}%''">
                        
                    <FilterParameters>
                        <asp:ControlParameter ControlID="ddlDivision" Name="DivisionName" 
                                                 PropertyName="SelectedValue" Type="String" />
                    </FilterParameters>

                    <SelectParameters>
                        <%--ControlParameter is linked to the HiddenField above to generate different GridView based on different values 
                            of GroupID--%>
                        <asp:ControlParameter ControlID="HiddenField1" Name="GroupID" PropertyName="Value" />
                    </SelectParameters>
                </asp:SqlDataSource>

                <div id="divGrid" class="tableDiv" style=" width:900px">
                <asp:GridView ID="GridView1" runat="server" 
                                AllowSorting="True" 
                                CellPadding="3" 
                                DataSourceID="SqlDataSource1" 
                                ClientIDMode="Static" class="fixedTables" Width="600" AutoGenerateColumns="true"
                                AlternatingRowStyle-CssClass="alt" 
                                RowStyle-HorizontalAlign="Center" 
                                OnRowDataBound="GridView1_RowDataBound" OnPreRender="GridView1_PreRender" OnRowCreated="GridView1_RowCreated">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <HeaderStyle Font-Bold = "true" ForeColor="Black"/> 
                    <Columns>
                    </Columns>
                    <EditRowStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#E9E7E2" />
                    <SortedAscendingHeaderStyle BackColor="#506C8C" />
                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                </asp:GridView>
                </div>



隐藏第一列的代码是:



And the code-behind for hiding the first column is:

//This method is for deleting the first column in the GridView
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false; // hides the first column
    }

推荐答案

ConnectionStrings:testConnectionString%> SelectCommandType ="StoredProcedure" SelectCommand ="kbiReport" FilterExpression ="[DivisionName]之类的"{0}%""> < FilterParameters> < asp:ControlParameter ControlID ="ddlDivision" Name ="DivisionName" PropertyName ="SelectedValue" Type ="String"/> </FilterParameters> < SelectParameters> <%-ControlParameter链接到上面的HiddenField,以基于不同的值生成不同的GridView 的GroupID-%> < asp:ControlParameter ControlID ="HiddenField1" Name ="GroupID" PropertyName ="Value"/> </SelectParameters> </asp:SqlDataSource> < div id ="divGrid" class ="tableDiv" style ="width:900px"> < asp:GridView ID ="GridView1" runat ="server" AllowSorting =真" CellPadding ="3" DataSourceID ="SqlDataSource1" ClientIDMode ="Static" class ="fixedTables" Width ="600" AutoGenerateColumns ="true" AlternatingRowStyle-CssClass ="alt" RowStyle-Horizo​​ntalAlign ="Center" OnRowDataBound ="GridView1_RowDataBound" OnPreRender ="GridView1_PreRender" OnRowCreated ="GridView1_RowCreated"> < AlternatingRowStyle BackColor ="White" ForeColor =#284775"/> < HeaderStyle Font-Bold ="true" ForeColor ="Black"/> <列> </列> < EditRowStyle BackColor =#999999"/> < FooterStyle BackColor =#5D7B9D" Font-Bold ="True" ForeColor ="White"/> < PagerStyle BackColor =#284775" ForeColor ="White" Horizo​​ntalAlign ="Center"/> < RowStyle BackColor =#F7F6F3" ForeColor =#333333"/> < SelectedRowStyle BackColor =#E2DED6" Font-Bold ="True" ForeColor =#333333"/> < SortedAscendingCellStyle BackColor =#E9E7E2"/> < SortedAscendingHeaderStyle BackColor =#506C8C"/> < SortedDescendingCellStyle BackColor =#FFFDF8"/> < SortedDescendingHeaderStyle BackColor =#6F8DAE"/> </asp:GridView> </div>
ConnectionStrings:testConnectionString %>" SelectCommandType="StoredProcedure" SelectCommand="kbiReport" FilterExpression="[DivisionName] like ''{0}%''"> <FilterParameters> <asp:ControlParameter ControlID="ddlDivision" Name="DivisionName" PropertyName="SelectedValue" Type="String" /> </FilterParameters> <SelectParameters> <%--ControlParameter is linked to the HiddenField above to generate different GridView based on different values of GroupID--%> <asp:ControlParameter ControlID="HiddenField1" Name="GroupID" PropertyName="Value" /> </SelectParameters> </asp:SqlDataSource> <div id="divGrid" class="tableDiv" style=" width:900px"> <asp:GridView ID="GridView1" runat="server" AllowSorting="True" CellPadding="3" DataSourceID="SqlDataSource1" ClientIDMode="Static" class="fixedTables" Width="600" AutoGenerateColumns="true" AlternatingRowStyle-CssClass="alt" RowStyle-HorizontalAlign="Center" OnRowDataBound="GridView1_RowDataBound" OnPreRender="GridView1_PreRender" OnRowCreated="GridView1_RowCreated"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <HeaderStyle Font-Bold = "true" ForeColor="Black"/> <Columns> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> </div>



隐藏第一列的代码是:



And the code-behind for hiding the first column is:

//This method is for deleting the first column in the GridView
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false; // hides the first column
    }





在下拉列表的选定索引更改事件上,隐藏gridview列,如下所示.


Hi,


On selected index changeed event of your dropdown list hide the gridview column as follows.


protected void yourdropdownid_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DLState.SelectedItem.Text == "All")
            {
                GridView1.Columns[0].Visible = true;
            }
            else
            {
                GridView1.Columns[0].Visible = false;
            }
        }




希望这会有所帮助.




Hope this helps.


这篇关于如何隐藏DropDownList筛选器中除All值之外的所有值的GridView中的第一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆