Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

cant get dropdown list bound to data in template column of gridvie

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 20 May 2008 22:12 GMT
Hi I have a generic list of data
list <type> listcategory;
listcategory = new list <type>;
I also have a dropdown box that I have put into a template column of a
gridview.
I was able to populate the dropdown box ok when it was outside of the gridview

for (int i = 0; i <= listcategory.Count - 1; i++)
       {
           ddl.Items.Add(listcategory[i].Description);
       }

Now that the control is in the gridview, ddl is not recognized.

I tried the following event but it does not seem to be reaching it.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs   e)
   {
;
}
I also tried the template edit from the gridview properties but could not
see how to bind the dropdown box to the items listcategory[i].Description.
Thanks.
Signature

Paul G
Software engineer.

Lee Thorpe - 20 May 2008 22:33 GMT
Paul

You need to use FindControl within your RowDataBound event-handler, i.e.

protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
   DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;

   if (ddl != null)
   {
       // Databind, or populate ListItems in a loop.
   }

}

> Hi I have a generic list of data
> list <type> listcategory;
[quoted text clipped - 20 lines]
> see how to bind the dropdown box to the items listcategory[i].Description.
> Thanks.
Lee Thorpe - 20 May 2008 22:34 GMT
Paul

You need to use FindControl within your RowDataBound event-handler, i.e.

protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
   DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;

   if(ddl != null)
   {
       // Databind, or populate ListItems in a loop.
   }
}

> Hi I have a generic list of data
> list <type> listcategory;
[quoted text clipped - 20 lines]
> see how to bind the dropdown box to the items listcategory[i].Description.
> Thanks.
Paul - 20 May 2008 23:08 GMT
thanks that worked!.  Just had an additional question, I need the grid to
have 2 dropldown boxes but want the other fields to be two empty text box
columns for data entry, and a checkbox column for bool entry as well as a
final row count column,(just displays the row count).  I had to bind the grid
to results of a dataset just to get the grid to show up so it currently has
extra undesired data from this dataset.  Should I just create an empty
dataset and bind it to so a single row with two dropdowns and the other
fields discribed above show up?
Also I noticed there is no way to add a new row within the control, so
guessing this might have to be done outside the control.
Paul G
Software engineer.

> Paul
>
[quoted text clipped - 35 lines]
> > see how to bind the dropdown box to the items listcategory[i].Description.
> > Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.