如何获取gridview行值并将其添加到下拉列表 [英] how to get gridview row value and add to dropdownlist

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

问题描述

如何获取gridview行值并将其添加到dropdownlist

解决方案

在这里,我从存档的集合中获取了一些代码...
可能会对您有帮助.

 私有 System.Windows.Forms.DataGridView Localdg;
私有 System.Windows.Forms.ListBox Plist;
// 您必须将其从设计器中拉入您的应用程序
 int  crcnt = Localdg.Rows.Add();
Localdg.Rows [crcnt] .Cells [ 0 ].Value = " ;
Localdg.Rows [crcnt] .Cells [ 1 ].Value = " ;
 foreach (DataGridViewRow DelR  in  Localdg.Rows中)
            {
                尝试
                {
                    Plist.Items.Add(DelR.Cells [ 0 ].Value.ToString()+ " ," + DelR.Cells [捕获 {}
            } 




它只是您的问题的一点参考..:)
对不起,我已经为您提供了listBox的代码,您可以为dropdownlist进行相应的修改.

for(int i=0;i<gridview1.rows.count;i++)>
{
GridViewRow=GridView1.Rows[i];
string strValue=GridView1.Rows[i].cells[0].ToString();
DropDownList1.Items.Add(strValue);
}


how to get gridview row value and add to dropdownlist

解决方案

Here I have got a few codes from my archived collection...
May be it will help you.

private System.Windows.Forms.DataGridView Localdg;
private System.Windows.Forms.ListBox Plist;
//You have to pull this from designer into your application
int crcnt = Localdg.Rows.Add();
Localdg.Rows[crcnt].Cells[0].Value = "Hello";
Localdg.Rows[crcnt].Cells[1].Value = "World";
foreach (DataGridViewRow DelR in Localdg.Rows)
            {
                try
                {
                    Plist.Items.Add(DelR.Cells[0].Value.ToString() + " , " + DelR.Cells[1].Value.ToString() );
                }
                catch { }
            }




Its just a little reference for your problem.. :)
EDIT: Sorry,I have given you this code for listBox, you can modify accordingly for dropdownlist.


its very simple to get gridview row value and insert into dropdownlist

for(int i=0;i<gridview1.rows.count;i++)>
{
GridViewRow=GridView1.Rows[i];
string strValue=GridView1.Rows[i].cells[0].ToString();
DropDownList1.Items.Add(strValue);
}


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

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