根据下拉列表显示gridview [英] Display gridview based on dropdownlist

查看:79
本文介绍了根据下拉列表显示gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助



我的网页上有一个下拉列表和一个gridview。



Gridview必须根据下拉列表项目选择显示....直到它不应显示Gridview。



从下拉列表中选择项目时,只显示Gridview。



提前感谢。

please help

I have a dropdownlist and a gridview on my webpage.

Gridview must be displayed based on dropdownlist item selection....till that it should not display Gridview.

Only Gridview must be displayed when item selected from dropdownlist.

thanks in advance.

推荐答案

<asp:DropDownList ID="ddlView" runat="server"

        onselectedindexchanged="ddlView_SelectedIndexChanged" AutoPostBack="true">
        <asp:ListItem Value="Select" Text="Select.."></asp:ListItem>
    <asp:ListItem Value="FirstGrid" Text="First Grid"></asp:ListItem>
     <asp:ListItem Value="SecondGrid" Text="Second Grid"></asp:ListItem>
      <asp:ListItem Value="ThirdGrid" Text="Third Grid"></asp:ListItem>
    </asp:DropDownList>
   <asp:GridView ID="gvFirst" runat="server">
   </asp:GridView>
   <asp:GridView ID="gvSecond" runat="server">
   </asp:GridView>
   <asp:GridView ID="gvThird" runat="server"></asp:GridView>





代码背后是



Code Behind is

protected void ddlView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlView.SelectedValue.ToString() == "Select")
            {
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();
            
            }
            else if (ddlView.SelectedValue.ToString() == "FirstGrid")
            {
                DataTable table = new DataTable();               
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("First Grid");
                gvFirst.DataSource = table;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();
                
            }
            else if (ddlView.SelectedValue.ToString() == "SecondGrid")
            {
                DataTable table = new DataTable();
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("Second Grid");
                gvSecond.DataSource = table;
                gvSecond.DataBind();
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();

            }
            else
            {
                DataTable table = new DataTable();
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("Third Grid");
                gvThird.DataSource = table;
                gvThird.DataBind();
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();

            }
        }


让我为您搜索: -



让我搜索你 [ ^ ]



希望它会帮助你。
Let me search this for you :-

Le me search for you[^]

Hope it will help you.


这篇关于根据下拉列表显示gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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