Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cant get dropdown list bound to data in template column of gridvie

Reply
Thread Tools

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

 
 
Paul
Guest
Posts: n/a
 
      05-20-2008
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.
--
Paul G
Software engineer.
 
Reply With Quote
 
 
 
 
Lee Thorpe
Guest
Posts: n/a
 
      05-20-2008
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.
}

}


"Paul" <> wrote in message
news:6250B943-3984-44D3-8960-...
> 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.
> --
> Paul G
> Software engineer.


 
Reply With Quote
 
 
 
 
Lee Thorpe
Guest
Posts: n/a
 
      05-20-2008
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.
}
}


"Paul" <> wrote in message
news:6250B943-3984-44D3-8960-...
> 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.
> --
> Paul G
> Software engineer.


 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      05-20-2008
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.


"Lee Thorpe" wrote:

> 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.
> }
> }
>
>
> "Paul" <> wrote in message
> news:6250B943-3984-44D3-8960-...
> > 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.
> > --
> > Paul G
> > Software engineer.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Design mode issue (bug?) in AJAX UpdatePanel w/UserControl+GridVie Eric ASP .Net 0 05-22-2009 03:17 PM
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Cant get data from template column into database =?Utf-8?B?Sk1B?= ASP .Net 2 09-01-2005 11:42 AM
Bound Column or Template Column (w dAdapater?) in DataGrid Ravichandran Mahalingam ASP .Net Datagrid Control 0 01-09-2004 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57