473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

Hi I have a generic list of data
list <typelistcategory;
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.
Jun 27 '08 #1
3 1697
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" <Pa**@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
Hi I have a generic list of data
list <typelistcategory;
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.
Jun 27 '08 #2
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" <Pa**@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
Hi I have a generic list of data
list <typelistcategory;
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.
Jun 27 '08 #3
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" <Pa**@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
Hi I have a generic list of data
list <typelistcategory;
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.

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Doslil | last post by:
I have a form which has a subform.In the main form I have only one field (this is a drop down list and has a query attached to it) which selects empno,Name from the EmployeeInformation table. ...
3
by: Dmitry Korolyov [MVP] | last post by:
Is that possible? In other words, I want a dropdown list (and other list-type controls) which appears in edit more of a templated column to be populated with data at the run time. An attempt to do so...
0
by: ba | last post by:
I'm using asp.net 2.0 and am writing a webform using the formview control. The <%# Bind("") %> syntax makes sense for textboxes, but I cannot figure out how to bind a dropdown list to a column....
2
by: JMA | last post by:
I have a detail view that i use for database updates. The regular fields work fine. I created a few drop down list templates and they dont seem to update the database for some reason. I have tried...
1
by: Mike C | last post by:
I'm new to Web development so I'm doing some bootstrapping and would really appreciate any help. Been grappling with this for days and am utterly confused by all the information on the web. I have...
3
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not...
2
by: Sam | last post by:
A) Destination Table with 4 Fields. 1) Last Name 2) First Name 3) State 4) Zip Code. B) Look up table State/Zip Code with 2 Fields
2
by: William Youngman | last post by:
We are developing an application that presents data to the user in a gridview and we are using the dropdown extender to give the user a SharePoint 2007 type dropdown menu attached to the cells of a...
1
by: kashifsulemani | last post by:
Combo Box DropDown Style. A combo box is bound to a data table field name. When combo box has simple / drop down style then bound is successful. Other hand if Combo box has drop down list...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.