Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Object Based Datagrid Tempate column binding

Reply
Thread Tools

Object Based Datagrid Tempate column binding

 
 
=?Utf-8?B?SGFyb2xk?=
Guest
Posts: n/a
 
      04-28-2004
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
 
Reply With Quote
 
 
 
 
avnrao
Guest
Posts: n/a
 
      04-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
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
Binding multi column values in one column Larry R ASP .Net 1 06-08-2007 06:27 AM
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
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
how to Add different controls(textBox,DropDownList or some ) in the same column,based upon the value in the previous column (Say second Colum which contain dropdown with some values) ? Balaji ASP .Net Datagrid Control 0 07-07-2003 08:32 AM
Tempate Operator Question sam C++ 0 06-27-2003 12:00 AM



Advertisments