Link to home
Start Free TrialLog in
Avatar of Mike_Stevens
Mike_StevensFlag for United States of America

asked on

Populate Dropdownlist in Gridview using function

I have a function that I use to populate dropdownlist on web forms with values from a SQL database.   I have a dropdown list inside of a gridview that is in a template column that i want to populate using that same function.  I think i have done this before but can figure it out.  Any help would be appreciated
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Use the RowDataBound event

http://forums.asp.net/t/1212101.aspx
Avatar of JosephEricDavis
JosephEricDavis

You'll have to do this inside of the gridview.OnRowDataBound event, like this...

 
protected void gvYourGridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
	//Check to make sure the databound row is one of the data rows and not the header
	if (e.Row.RowType == DataControlRowType.DataRow)
	{
		DropDownList ddl = e.Row.FindControl("IdOfYourDropDownListControlInTheTemplateColumn") as DropDownList;
		//Run your data function on the ddl
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rick
Rick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I forgot... you need to have that inside a for each loop:

   for each gridviewrow In gridview1.rows


Or use the gridview's RowDataBound event, like like CodeCruiser and JosephEricDaves mentioned.