GURU HELP??? Dropdown List in Datagrid Footer

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Sep 22, 2004.

  1. Can some please tell me why this dropdown list isn't getting populated in my
    datagrid! I don't get any error the datagrid just doesn't populate. I would
    appritiate any examples.

    Thanks

    ...::Inline Code

    <FooterTemplate>
    <!-- Pull Office Names from Database -->
    <asp:DropDownList id="DDLaddOffice" runat="server"></asp:DropDownList>
    </FooterTemplate>

    ...::CODEBEHIND

    Private Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs)

    'Construct the Database Connection
    Dim Myconn As New
    SqlConnection(ConfigurationSettings.AppSettings("strConn"))
    Dim cmd As New SqlCommand("SelectOffice", Myconn)


    If e.Item.ItemType = ListItemType.Footer Then


    cmd.CommandType = CommandType.StoredProcedure

    Myconn.Open()

    Dim add_Office As DropDownList

    'Payment Method Dll - create, fill and preselect

    add_Office = CType(e.Item.FindControl("DDLaddOffice"),
    DropDownList)
    add_Office.DataSource =
    cmd.ExecuteReader(CommandBehavior.CloseConnection)
    add_Office.DataBind()
    add_Office.Items.Insert(0, "Select One")
    add_Office.Items.FindByText("Select One").Value = 0 'insert
    don't create a value, but we need a value during defaults
    add_Office.SelectedIndex = 0
    End If

    End Sub
    =?Utf-8?B?VGltOjouLg==?=, Sep 22, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?VGltOjouLg==?=

    GrantMagic Guest

    Have you set the datagrid's OnItemDataBound:
    i.e. OnItemDataBound = "populateDDL_ItemDataBound"

    If that is not that case,
    try populating the datalist manually in the databound command i.e. not using
    a database, just add_Office.Items.Insert(0, "Select One").
    This will determine if it is the binding that is the problem, or something
    with your method.
    But it looks fine to me

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Can some please tell me why this dropdown list isn't getting populated in
    > my
    > datagrid! I don't get any error the datagrid just doesn't populate. I
    > would
    > appritiate any examples.
    >
    > Thanks
    >
    > ..::Inline Code
    >
    > <FooterTemplate>
    > <!-- Pull Office Names from Database -->
    > <asp:DropDownList id="DDLaddOffice" runat="server"></asp:DropDownList>
    > </FooterTemplate>
    >
    > ..::CODEBEHIND
    >
    > Private Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs)
    >
    > 'Construct the Database Connection
    > Dim Myconn As New
    > SqlConnection(ConfigurationSettings.AppSettings("strConn"))
    > Dim cmd As New SqlCommand("SelectOffice", Myconn)
    >
    >
    > If e.Item.ItemType = ListItemType.Footer Then
    >
    >
    > cmd.CommandType = CommandType.StoredProcedure
    >
    > Myconn.Open()
    >
    > Dim add_Office As DropDownList
    >
    > 'Payment Method Dll - create, fill and preselect
    >
    > add_Office = CType(e.Item.FindControl("DDLaddOffice"),
    > DropDownList)
    > add_Office.DataSource =
    > cmd.ExecuteReader(CommandBehavior.CloseConnection)
    > add_Office.DataBind()
    > add_Office.Items.Insert(0, "Select One")
    > add_Office.Items.FindByText("Select One").Value = 0 'insert
    > don't create a value, but we need a value during defaults
    > add_Office.SelectedIndex = 0
    > End If
    >
    > End Sub
    GrantMagic, Sep 22, 2004
    #2
    1. Advertising

  3. Thanks! You where correct about the OnItemDataBound

    Kind Regards

    Alan

    "GrantMagic" wrote:

    > Have you set the datagrid's OnItemDataBound:
    > i.e. OnItemDataBound = "populateDDL_ItemDataBound"
    >
    > If that is not that case,
    > try populating the datalist manually in the databound command i.e. not using
    > a database, just add_Office.Items.Insert(0, "Select One").
    > This will determine if it is the binding that is the problem, or something
    > with your method.
    > But it looks fine to me
    >
    > "Tim::.." <myatix_at_hotmail.com> wrote in message
    > news:...
    > > Can some please tell me why this dropdown list isn't getting populated in
    > > my
    > > datagrid! I don't get any error the datagrid just doesn't populate. I
    > > would
    > > appritiate any examples.
    > >
    > > Thanks
    > >
    > > ..::Inline Code
    > >
    > > <FooterTemplate>
    > > <!-- Pull Office Names from Database -->
    > > <asp:DropDownList id="DDLaddOffice" runat="server"></asp:DropDownList>
    > > </FooterTemplate>
    > >
    > > ..::CODEBEHIND
    > >
    > > Private Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As
    > > System.Web.UI.WebControls.DataGridItemEventArgs)
    > >
    > > 'Construct the Database Connection
    > > Dim Myconn As New
    > > SqlConnection(ConfigurationSettings.AppSettings("strConn"))
    > > Dim cmd As New SqlCommand("SelectOffice", Myconn)
    > >
    > >
    > > If e.Item.ItemType = ListItemType.Footer Then
    > >
    > >
    > > cmd.CommandType = CommandType.StoredProcedure
    > >
    > > Myconn.Open()
    > >
    > > Dim add_Office As DropDownList
    > >
    > > 'Payment Method Dll - create, fill and preselect
    > >
    > > add_Office = CType(e.Item.FindControl("DDLaddOffice"),
    > > DropDownList)
    > > add_Office.DataSource =
    > > cmd.ExecuteReader(CommandBehavior.CloseConnection)
    > > add_Office.DataBind()
    > > add_Office.Items.Insert(0, "Select One")
    > > add_Office.Items.FindByText("Select One").Value = 0 'insert
    > > don't create a value, but we need a value during defaults
    > > add_Office.SelectedIndex = 0
    > > End If
    > >
    > > End Sub

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Sep 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    DataGrid and JavaScript GURU...

    =?Utf-8?B?VGltOjouLg==?=, Jul 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,507
    =?Utf-8?B?VGltOjouLg==?=
    Jul 18, 2005
  2. vishnu
    Replies:
    1
    Views:
    1,202
    Patrick.O.Ige
    Mar 25, 2006
  3. Matt

    Footer not in datagrid items list

    Matt, Jun 30, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    192
    Colin Young
    Jul 1, 2003
  4. Edward Bills

    Dropdown in footer template of datagrid

    Edward Bills, Jul 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    372
    Edward Bills
    Jul 22, 2004
  5. Henrik
    Replies:
    1
    Views:
    423
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page