将值添加到下拉列表 [英] add values to dropdownlist

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

问题描述

在这里,我想用Asp.net在C#中以编程方式将值添加到dropdownlist中(在这里我想从数据库表中获取值).我想使一个通用函数不用于dropdownlist控件.解决这个问题.
在我的项目中,我想将状态名称添加到下拉列表中.请帮助我.向我发送此函数的代码.

here, I want to add values into dropdownlist programatically(here i want to get values from database table) in c# with Asp.net.I want to make acommon function to use for no of dropdownlist control.so, please help me to solve this problem.
In my project,I want to add state names into dropdownlist.Please help me..SEnd me code for this function.

推荐答案

Try
Try
public void AddDropDownList(DropDownList obj,string[] arr)
   {
       for (int i = 0; i < arr.Length; i++)
       {
           obj.Items.Add(arr[i]);
       }
   }


您可以使用函数此函数以给定的方式存储值


you can use function this function to store values in given ways

string[] arr = { Names of States };
      AddDropDownList(DropDownList1, arr); // Storing Names of State to DropDownList1 Control


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

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