Re: How to bind to a drop down list in a grid.
From: Michael Tkachev (m_tkachev_at_hotmail.com)
Date: 12/02/04
- Next message: Travis Murray: "Re: How to keep a DataGrid in sync with a DataSet when sorting"
- Previous message: Eliyahu Goldin: "Re: Data Grid"
- In reply to: Eric: "How to bind to a drop down list in a grid."
- Messages sorted by: [ date ] [ thread ]
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>
>
>
>
- Next message: Travis Murray: "Re: How to keep a DataGrid in sync with a DataSet when sorting"
- Previous message: Eliyahu Goldin: "Re: Data Grid"
- In reply to: Eric: "How to bind to a drop down list in a grid."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|