绑定Dropdownlist通用方法

[ 1403 查看 / 0 回复 ]

//CurrentValue:绑定Dropdownlist后的选中项
public void BoundDropDownList(DropDownList dropDownList,string ColText,
                        string ColValue,DataTable dataTable,long CurrentValue)
                {
                        dropDownList.DataSource=dataTable;
                        dropDownList.DataTextField=ColText;
                        dropDownList.DataValueField=ColValue;
                        dropDownList.DataBind();
                        foreach(ListItem item in dropDownList.Items)
                        {
                                try
                                {
                                        if(Convert.ToInt64(item.Value)==CurrentValue)
                                        {
                                                item.Selected=true;
                                                break;
                                        }
                                }
                                catch
                                {
                       
                                }
                        }
                }
最后编辑chengang0535 最后编辑于 2009-11-29 08:43:19
TOP