Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get gridview row value and add to dropdownlist
Posted
Comments
Prabhakaran Soundarapandian 15-Mar-12 6:42am    
Do you need to get all the cell values from a particular selected row?

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);
}
 
Share this answer
 
Here I have got a few codes from my archived collection...
May be it will help you.

C#
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.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900