nick轩

导航

在gridview中使用dropdownlist的方法

在页面:

<asp:TemplateField HeaderText="公司">

  <ItemTemplate>

    <asp:DropDownList ID="ddlCompany" runat="server" DataSource="<%# BindCompany() %>" DataTextField="ShortName"  DataValueField="Id" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" AutoPostBack="true">

    </asp:DropDownList>

        </ItemTemplate>

</asp:TemplateField>

在后台:

 

        protected DataTable BindCompany()

        {

            // 获取公司

            BaseOrganizeManager organizeManager = new BaseOrganizeManager(this.UserCenterDbHelper, this.UserInfo);//Nick change database

            DataTable dataTable = organizeManager.GetCompanyDT(String.Empty);

            // 用过滤器进行过滤,只显示有效的数据。

            BaseBusinessLogic.SetFilter(dataTable, BaseOrganizeTable.FieldEnabled, "1");

            BaseBusinessLogic.SetFilter(dataTable, BaseOrganizeTable.FieldDeleteMark, "0");

            BaseBusinessLogic.SetFilter(dataTable, BaseOrganizeTable.FieldIsInnerOrganize, "1");

            DataRow dr;

            dr = dataTable.NewRow();

            dataTable.Rows.InsertAt(dr, 0);

            return dataTable;

        }

使用DropDownList:

 

        protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)

        {

            GridViewRow gvr = (GridViewRow)((Control)sender).Parent.Parent;

            DropDownList ddlCompany = (DropDownList)gvr.FindControl("ddlCompany");

            DropDownList ddlSubOrg = (DropDownList)gvr.FindControl("ddlSubOrg");

            DropDownList ddlDept = (DropDownList)gvr.FindControl("ddlDept");

            DropDownList ddlWorkgroup = (DropDownList)gvr.FindControl("ddlWorkgroup");

 

            this.GetSubOrgList(ddlCompany.SelectedValue, ddlSubOrg);

            this.GetDeptList(ddlCompany.SelectedValue, ddlDept);

            this.GetWorkgroupList(ddlSubOrg.SelectedValue, ddlWorkgroup);

        }

 

 

posted on 2011-01-10 19:24  nick轩  阅读(598)  评论(0编辑  收藏  举报