下拉列表默认值 [英] Dropdown list default value

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

问题描述

大家好,
我有一个下拉列表ddlUnitCode,该列表在存储过程的pageload事件中填充.当用户登录时,我正在将他的单位代码捕获到局部变量中,并且希望使用局部变量的特定值来选择ddlUnitCode.

Hi Everybody,
I have a dropdown list ddlUnitCode which gets populated on pageload event from a stored procedure. When a user login I am capturing his unitcode in a local variable and I want that the ddlUnitCode should be selected with the particular value of the local variable.

if (!IsPostBack)
        {
            //Filling up the dropdownlit ddlUnit
            ddlUnit.DataSource = Service.GetUnitCode();
            ddlUnit.DataTextField = "UnitCode";
            ddlUnit.DataValueField = "UnitCode";
            ddlUnit.DataBind();
            ddlUnit.Items.Insert(0, "All");

            //Filling up dropdown month with month name
            ddlMonth.Items.Add("All");
            for (int i = 0; i <= 11; i++)
            {                  ddlMonth.Items.Add(CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[i]);
            }

            //Hiding the controls
            ddlMonth.Visible = false;
            tbSearchDateOfBirth.Visible = false;
            ibtnSearchDateOfBirth.Visible = false;
            btnSearch.Visible = false;
            
            //Geting the unitcode of the user from a function..
            string  CurrentUserUnit = Service.GetUserUnitCode();

            //Now I want that ddlUnit should by default be focused with CurrentUserUnit .I have tried this below code but in vein
            ddlUnit.SelectedIndex = ddlUnit.Items.IndexOf(ddlUnit.Items.FindByValue(CurrentUserUnit));

            //But the above code does not helped me out.....


        }



希望尽快解决此问题.提前谢谢..

Animesh Chatterjee
学习者



Hope to Resolve the issue soon. Thanks in advance..

Animesh Chatterjee
A Learner

推荐答案

尝试:
ddlUnit.Text = CurrentUserUnit;



此处: ListControl.Text属性 [ ^ ]



Here: ListControl.Text Property [^]


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

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