objectdatasource

本文介绍了一个基于ASP.NET的用户管理界面实现细节,包括如何根据用户数据动态更新界面元素,如性别、会员等级等,并提供了针对不同操作模式(如只读和编辑)的界面定制方法。此外,还涉及了数据过滤表达式的构建与应用。
摘要由CSDN通过智能技术生成

public partial class Admin_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
              
       
        if (!IsPostBack)
        {
            

        }

    }
    public string Filter
    {
        get
        {
            if (this.ViewState["filterExpression"] != null)
                return (string)this.ViewState["filterExpression"];
            return string.Empty;
        }
        set
        {
            this.ViewState["filterExpression"] = value;

        }
    }

    protected void dvUser_DataBound(object sender, EventArgs e)
    {
        if (dvUser.CurrentMode == DetailsViewMode.ReadOnly)
        {
           
            if (dvUser.Rows.Count > 0)
            {
                Label lblSex = (Label)dvUser.FindControl("lblSex");
                Label lblLevel = dvUser.FindControl("lblLevel") as Label;
                DataRowView row = (DataRowView)this.dvUser.DataItem;

                if (row["F_Sex"].ToString() == "0")
                    lblSex.Text = "男";
                else
                    lblSex.Text = "女";
                switch (row["F_Level"].ToString())
                {
                    case "0":
                        lblLevel.Text = "普通会员";
                        break;
                    case "1":
                        lblLevel.Text = "银卡会员";
                        break;
                    case "2":
                        lblLevel.Text = "金卡会员";
                        break;

                }
            }         
        }
        if (dvUser.CurrentMode == DetailsViewMode.Edit)
        {
            DropDownList ddlLevel = dvUser.FindControl("ddlLevel") as DropDownList;
            DataRowView row = (DataRowView)this.dvUser.DataItem;

            ddlLevel.SelectedValue = row["F_Level"].ToString();
        }
    }
    protected void dvUser_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
       
    }
    protected void dvUser_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        if (dvUser.CurrentMode == DetailsViewMode.Edit)
        {
            DropDownList ddlLevel = dvUser.FindControl("ddlLevel") as DropDownList;
            TextBox TextBox1 = dvUser.FindControl("TextBox1") as TextBox;
            //odUser.UpdateParameters["Level"].DefaultValue = ddlLevel.SelectedValue;
           

        }
    }
    protected void odUser_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
        e.InputParameters["level"] = ((DropDownList)dvUser.FindControl("ddlLevel")).SelectedValue;
       
    }
    protected void odUser_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
        gvUserCompany.DataSourceID = "ODUserCompany";
        GetFilterExpression();
    }
    protected void dvCompany_DataBound(object sender, EventArgs e)
    {
        if (dvCompany.CurrentMode == DetailsViewMode.ReadOnly)
        {
            if (dvUser.Rows.Count > 0)
            {
                Label lblProPerty = dvCompany.FindControl("lblProPerty") as Label;
               
                Label lblIsTop = dvCompany.FindControl("lblIsTop") as Label;
                DataRowView row = this.dvCompany.DataItem as DataRowView;
                if (row != null)
                {
                    switch (row["F_ProPerty"].ToString())
                    {
                        case "1":
                            lblProPerty.Text = "企业单位";
                            break;
                        case "2":
                            lblProPerty.Text = "个体经营";
                            break;
                        case "3":
                            lblProPerty.Text = "事业单位或者社会团体";
                            break;
                        default:
                            break;

                    }

                    if (row["F_IsTop"].ToString() == "1")
                        lblIsTop.Text = "推荐企业";
                    else
                        lblIsTop.Text = "普通企业";

 
                }
               
            }
          
 
        }
        if (dvCompany.CurrentMode == DetailsViewMode.Edit)
        {
            DropDownList ddlIsTop = dvCompany.FindControl("ddlIsTop") as DropDownList;
            DataRowView row = this.dvCompany.DataItem as DataRowView;
            ddlIsTop.SelectedValue = row["F_IsTop"].ToString();
 
        }
      
    }
    protected void odCompany_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
        e.InputParameters["istop"] = ((DropDownList)dvCompany.FindControl("ddlIsTop")).SelectedValue;
    }
    protected void odCompany_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
        gvUserCompany.DataSourceID = "ODUserCompany";
        GetFilterExpression();
       
    }
    protected void gvUserCompany_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
             
    }
    protected void gvUserCompany_RowDataBound(object sender, GridViewRowEventArgs e)   
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            //{               
            //}
            Label lblIsTop = e.Row.FindControl("lblIsTop") as Label;
            Label lblLevel = e.Row.FindControl("lblLevel") as Label;
            DataRowView gv = (DataRowView)e.Row.DataItem;

            if (gv != null)
            {
                if (gv.Row["F_IsTop"].ToString() == "1")
                    lblIsTop.Text = "推荐企业";
                else if (gv.Row["F_IsTop"].ToString() == "0")
                    lblIsTop.Text = "普通企业";
                else
                    lblIsTop.Text = "";
                /*
                if (gv.Row["F_CheckStatus"].ToString()=="")
                e.Row.Cells[9].Text = "";
                 */
                switch (gv.Row["F_UserLevel"].ToString())
                {
                    case "0":
                        lblLevel.Text = "普通会员";
                        break;
                    case "1":
                        lblLevel.Text = "银卡会员";
                        break;
                    case "2":
                        lblLevel.Text = "金卡会员";
                        break;

                }
 
            }   
        }

    }
    protected void ODUserCompany_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
      
    }
    protected void GetFilterExpression()
    {
        if (ddlProvince.SelectedValue != "-1" && ddlProvince.SelectedValue != "0")
        {
            ODUserCompany.FilterExpression += " and F_ProvinceID=" + ddlProvince.SelectedValue;
        }
        if (ddlCity.SelectedValue != "-1" && ddlCity.SelectedValue != "0")
        {
            ODUserCompany.FilterExpression += " and F_CityID=" + ddlCity.SelectedValue;
        }
        if (ddlBigType.SelectedValue != "-1" && ddlBigType.SelectedValue != "0")
        {
            ODUserCompany.FilterExpression += " and F_IndustryID1=" + ddlBigType.SelectedValue;
        }
        if (ddlSmallType.SelectedValue != "-1" && ddlSmallType.SelectedValue != "0")
        {
            ODUserCompany.FilterExpression += " and F_IndustryID2=" + ddlSmallType.SelectedValue;
        }
 
    }
    protected void ODUserCompany_Filtering(object sender, ObjectDataSourceFilteringEventArgs e)
    {
    }

    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        Comm.DataBind(Comm.Execute_strSql_Re_Ds("select F_ID,F_Name from T_City Where F_Province_ID=" + ddlProvince.SelectedValue), ddlCity, "F_Name", "F_ID", true);
        GetFilterExpression();
    }
    protected void ddlBigType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Comm.DataBind(Comm.Execute_strSql_Re_Ds("select F_ID,F_Name from T_IndustryCategory where F_ParentID="+ddlBigType.SelectedValue), ddlSmallType, "F_Name", "F_ID", true);
        GetFilterExpression();
    }
    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetFilterExpression();
    }

    protected void ddlSmallType_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetFilterExpression();
    }
 
    protected void gvUserCompany_PageIndexChanged(object sender, EventArgs e)
    {
        GetFilterExpression();
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值