473,386 Members | 2,050 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,386 software developers and data experts.

Object Based Datagrid Tempate column binding

Hi all, having a little difficulty binding up a dropdownlist control in a datagrid column. I know I must be missing something

Here are 2 methods. One is the DataGrid's ItemDataBound event to catch the grid population event and the other is to populate the dropdownlist

I'll start with the method that binds the dropdownlist. As mentioned it is object based and also works fine everywhere but in a template column. I have put in some comments to illustrate what I am doing, please forgive if this is old hat to you

public static DropDownList RetrieveSalesPartners(ref DropDownList ddl

Employee searchCriteria = new Employee(); // instance the single objec
searchCriteria.DepartmentID = 1; // set department criteri
Employees employees = new Employees(); instance the many objec
employees.Retrieve(searchCriteria) // call the retieve methoth in the dataclass with criteria

foreach(Employee employee in employees

// loop through adding the employee
ListItem listItem = new ListItem(employee.LastName + ", " + employee.FirstName, employee.EmployeeID)
ddl.Items.Add(listItem)

return dd
the above works great and is commonplace for how we do things. The next part is my issu
I wire up the ItemDataBound event for the DataGrid control, lets call it dg

private void dg_ItemDateBound(object sender, DataGridItemEventArgs e

DropDownList tmpSalesPartner = (DropDownList) e.Item.FindControl("ddlSalesPartner")
string test = tmpSalesPartner.SelectedValue.ToString(); // this retrieves the test value I put on the control and work
RetrieveSalesPartners(ref tmpSalesPartner); // bombs on not an instance of the objec
Thats it in a nutshell. I can retrieve the value of the box but cant populate it dynamically. I have seen examples using datasets, views, ect but all my work is object based so I wont be using any of those. Again the RetrieveSalesPartners works perfectly on contrals not embedded in a grid. It actually is overloaded several times for reuse for other applications, different departments, ect but for brevity I dumbed it down to illustrate the point

If anyone can offer a suggestion I would be most appreciative. i'll keep plugging away at it but I know I must be ignorant of the datagrid control itself. Also this DropDownList is in the Header not items

Thanks again

Harold
Nov 18 '05 #1
1 1393
this error will come up when e.Item.FindControl could not find your control.
since dg_ItemDataBound doesnt have any filter like (e.Item.ItemType ==
ListItemType.Item or EditItem), its going to run the code for every call.
i would say double check to find out if you are actually getting your
control (do a response.write when the control is null).

Av.

"Harold" <harold@-take-this-bit-out-.dismang.com> wrote in message
news:5E**********************************@microsof t.com...
Hi all, having a little difficulty binding up a dropdownlist control in a
datagrid column. I know I must be missing something.
Here are 2 methods. One is the DataGrid's ItemDataBound event to catch the
grid population event and the other is to populate the dropdownlist.

I'll start with the method that binds the dropdownlist. As mentioned it is
object based and also works fine everywhere but in a template column. I
have put in some comments to illustrate what I am doing, please forgive if
this is old hat to you.

public static DropDownList RetrieveSalesPartners(ref DropDownList ddl)
{
Employee searchCriteria = new Employee(); // instance the single
object
searchCriteria.DepartmentID = 1; // set department criteria
Employees employees = new Employees(); instance the many object
employees.Retrieve(searchCriteria) // call the retieve methoth in
the dataclass with criterian

foreach(Employee employee in employees)
{
// loop through adding the employees
ListItem listItem = new ListItem(employee.LastName + ", " +
employee.FirstName, employee.EmployeeID);
ddl.Items.Add(listItem);
}
return ddl
}

the above works great and is commonplace for how we do things. The next
part is my issue
I wire up the ItemDataBound event for the DataGrid control, lets call it
dg.

private void dg_ItemDateBound(object sender, DataGridItemEventArgs e)
{
DropDownList tmpSalesPartner = (DropDownList)
e.Item.FindControl("ddlSalesPartner");
string test = tmpSalesPartner.SelectedValue.ToString(); // this
retrieves the test value I put on the control and works
RetrieveSalesPartners(ref tmpSalesPartner); // bombs on not an
instance of the object
}

Thats it in a nutshell. I can retrieve the value of the box but cant
populate it dynamically. I have seen examples using datasets, views, ect
but all my work is object based so I wont be using any of those. Again the
RetrieveSalesPartners works perfectly on contrals not embedded in a grid.
It actually is overloaded several times for reuse for other applications,
different departments, ect but for brevity I dumbed it down to illustrate
the point.

If anyone can offer a suggestion I would be most appreciative. i'll keep
plugging away at it but I know I must be ignorant of the datagrid control
itself. Also this DropDownList is in the Header not items.

Thanks again,

Harold

Nov 18 '05 #2

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

Similar topics

0
by: Tom Hughes | last post by:
I want to change one field of all selected rows to a provided value. Problem 1 I am using the Binding Manager Base to bind the datagrid to the appropriate dataTable as recommended by KB817247....
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
4
by: ShadowsOfTheBeast | last post by:
hi oliver thanks for your help i kinda figured that out minutes afterwards...but what i am actually trying to do is this: i have a listbox control that gets its data from another listbox (hence...
4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
1
by: BC | last post by:
Hi, Been searching the newgroups but haven't found an answer. I'm used to binding disconnected ADO recordsets to Datagrid controls and tweaking the Datagrid to suit my needs (columnheader,...
1
by: wh1974 | last post by:
I'm not sure if i'm heading in the right direction so would appreciate any comments on what I'm trying to do. Basically I have a DataGrid on a page which has columns whose width's I set in the...
2
by: Randall Parker | last post by:
Suppose you want to do either of these: A) Set display properties (e.g. color or boldness of text) of a cell based on a value of another cell in the same row. B) Set the display properties of...
3
by: reidarT | last post by:
I have a datagrid with columns. One of the columns are a textbox. I want the text in this column shown in a textbox outside the datagrid. How can I do that when clicking the actual row in the...
8
by: Matt | last post by:
Guys I could really use some help with this. I think that it's probably a simple solution but I haven't been able to find anything. I have a datagrid on my form that I populate via code like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.