displaying dropdown list values in edititemtemplate in gridview

Discussion in '.NET' started by sjmyers, Mar 27, 2007.

  1. sjmyers

    sjmyers

    Joined:
    Mar 27, 2007
    Messages:
    1
    Location:
    london
    im trying to populate a dropdown list in an EditItemTemplate in a gridview from a method. i can do this in a table (outside of a gridview), but am referencing the gridview incorrectly. the following code shows where i currently am:

    PricesAdmin.ascx:

    <asp:TemplateField HeaderText="Start Date" SortExpression="StartDate">
    <ItemTemplate>
    <asp:Label ID="Label6" runat="server" Text='<%# Eval("StartHour") %>' />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList ID="startHour" runat="server" CssClass="AdminPageText" SelectedValue='<%# Bind("StartHour") %>' />
    </EditItemTemplate>
    </asp:TemplateField>

    PricesAdmin.ascx.cs

    // method to populate dropdown list with hours of the day
    private void PopulateStartDate(object sender, GridViewEditEventArgs e)
    {
    // Fill Start and End Hours dropdown list
    for (int i = 0; i <= 23; i++)
    {
    // populate the list boxes
    if (i < 10)
    {
    startHour.Items.Add(new ListItem("0" + i.ToString(), i.ToString()));
    }
    else
    {
    startHour.Items.Add(new ListItem(i.ToString(), i.ToString()));
    }
    }
    }

    // Enter row into edit mode
    protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
    // set the row for which to enable edit mode
    grid.EditIndex = e.NewEditIndex;
    // Set status message
    statusLabel.Text = "Editing row # " + e.NewEditIndex.ToString();
    // Reload the grid
    BindGrid();
    PopulateEditableDateControls(sender, e);
    }
     
    sjmyers, Mar 27, 2007
    #1
    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?UGhpbGxpcCBXaWxsaWFtcw==?=

    RE: bind dropdown field in GridView EditItemTemplate?

    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Mar 21, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    9,771
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 21, 2006
  2. =?Utf-8?B?RGFiYmxlcg==?=

    bind dropdown field in GridView EditItemTemplate?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 21, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    30,151
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 23, 2006
  3. cindy@tams.com
    Replies:
    0
    Views:
    957
    cindy@tams.com
    Sep 20, 2006
  4. Brian Greiwe

    Can't get to nested dropdown in edititemtemplate column

    Brian Greiwe, Sep 16, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    168
    Brian Greiwe
    Sep 16, 2003
  5. Jacques Leclerc

    adding item to dropdown within edititemTemplate

    Jacques Leclerc, Dec 19, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    240
    Jacques Leclerc
    Dec 19, 2003
Loading...

Share This Page