Re: How to bind to a drop down list in a grid.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael Tkachev (m_tkachev_at_hotmail.com)
Date: 12/02/04


Date: Thu, 2 Dec 2004 17:03:34 +0300

Hi.

You wrote a mistake.
You have to write the code like this:

e.Item.Cells[1].FindControl("ddlRegion");

Now it returns your control. :)

Bye

Mike.

"Eric" <eric@nospam.com> wrote in message
news:%2300zwv$1EHA.3708@TK2MSFTNGP14.phx.gbl...
>
> I want to display some drop down lists in a grid. Let's say user Joe is
> from Region 1, and I want to get a list of users and bind to the grid, but
> want the Region column to be a drop down list displaying all regions with
> Joe's current value selected.
> I'm using templated columns, but cant get the data binding of the drop
down
> list correct. I bind the main grid in the Load event, and am trying to
find
> the right place to bind the lists, but to no avail. I tried in the
> ItemDataBound event, but you dont have access to the controls in the grid
> row at that point. If I try that code in a button handler invoked after
the
> page is created, it works ok.
>
> I have something like below. The FindControl method is returning null. I
> cant find an event during the load up that gives me access to the controls
> during the main loading sequence.
> Private Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> DataGrid2.ItemDataBound
> Dim ds As DataSet = BOReportsSecurityAdmin.GetDivisionRegionArea()
> Dim ddl As DropDownList = e.Item.FindControl("ddlRegion") 'Returns null
when
> called from inside ItemDataBound
> ddl.DataSource = ds.Tables(0)
> ddl.DataTextField = "Region"
> ddl.DataValueField = "RegionID"
> ddl.DataBind()
>
> End Sub
>
>
> -----------------------------------------------------
>
> Here are the two grid template columns in question:
>
> <asp:TemplateColumn HeaderText="User">
> <ItemTemplate>
> <asp:label RUNAT="server" TEXT='<%#
> DataBinder.Eval(Container.DataItem,"EntityName")%>' ID="lblUserCol"/>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText="Region">
> <ItemTemplate>
> <asp:DropDownList RUNAT="server" ID="ddlRegion" />
> </ItemTemplate>
> </asp:TemplateColumn>
>
>
>



Relevant Pages

  • How to bind to a drop down list in a grid.
    ... I want to display some drop down lists in a grid. ... Let's say user Joe is ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: very novice Find Button
    ... You can bind your grid or ... controls to either a DataTable or a Datview. ... If you have trouble with getting the found data to display, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: design guidance please :user controls and centralizing roles-r
    ... I'm curious to what extent you're thinking the layout and display ... I am fairly new to C#, lists, ... User controls need to be visible or not visible depending on user role. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Best way to proceed
    ... > One idea is to use a datagrid, that would initially have one empty row ... > with blanks or drop down lists as needed in each field (of grid). ... > display showing the new row of information that was just added ...
    (microsoft.public.dotnet.framework.aspnet)
  • Nested controls: possible workaround for limitation?
    ... I have created User controls that are display in an ... Within each list will be the actual list of members. ... results with lists of classes with members inside them and so on... ... So, I've made 4 controls, a RequestViewer, a ResultViewer, a ListViewer ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)