seofunctions.innerlink Saving page now... http://www.webmaster5u.com/xra/show.asp?id=2787 As it appears live March 3, 2020 3:09:47 AM UTC
,欢迎光临!
您当前位置:网站首页 >> 网络编程 >> .net >> dropdownlist获取项对应的DataValueField(如何获取选中的dropdownlist的项对应绑定数据的id(主键))

dropdownlist获取项对应的DataValueField(如何获取选中的dropdownlist的项对应绑定数据的id(主键))

2013-04-06 23:53:31 来源:旭日站长 浏览:83

动态搞笑图片  每日一笑话,快乐一辈子

dropdownlist获取项对应的DataValueField,我老是获取不正确,代码附上:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class WebFile_Department_addDepartmentCJ : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.ddl_department.DataSource = User1.returnsdr("all_department1_CJ");
            this.ddl_department.DataTextField = "DepartName";
            this.ddl_department.DataValueField = "DepartID";
            this.ddl_department.DataBind();


            User1.conClosed();
        }
    }
    protected void btn_ok_Click1(object sender, EventArgs e)
    {

        //string DeparthIndex = this.ddl_department.SelectedValue.ToString();
      
      
        int departh = int.Parse(this.ddl_department.SelectedValue);
        string DepartmentName = this.txt_dpmName.Text.ToString();
        //SqlParameter[] pars = { User1.ParamBuilder("DepartID", Convert.ToInt32(DeparthIndex), SqlDbType.Char), User1.ParamBuilder("@DepartName", DepartmentName, SqlDbType.Char) };
        SqlParameter[] pars = { User1.ParamBuilder("DepartID", departh, SqlDbType.Int), User1.ParamBuilder("@DepartName", DepartmentName, SqlDbType.Char) };

        if (User1.delUser("create_department", pars))
        {
            Response.Write("<script>alert('插入部门成功')</script>");
            Response.Write("<script>document.location=document.location;</script>");//弹窗窗体后刷新本页面
            Response.Redirect("listDepartment.aspx");
            

        }
       
    }

 

 

最后才知道是自己忘记加:

 if(!IsPostBack){
}造成的,所以大家遇到获取不到跟dropdownlist的项对应绑定数据的id时候看看是不是少了该句了

发表评论
网名:
评论:
验证:
共有0人对本文发表评论查看所有评论(网友评论仅供表达个人看法,并不表明本站同意其观点或证实其描述)
关于我们 - 联系我们 - 本站热点 - 会员中心 - 下载首页 - 版权声明
powered by 旭日软件(http://www.webmaster5u.com) 。
威尼斯人官网,旭日软件园-提供免费小软件下载,电脑教程和QQ表情包下载为主要宗旨.同时有网站运营,编程教程,网页特效,手机教程,游戏攻略和IT资讯等内容,打造常用软件下载、内容丰富的站长学习!
seofunctions.copyrightseofunctions.bdjs