displaying dropdown list values in edititemtemplate in gridview

Joined
Mar 27, 2007
Messages
1
Reaction score
0
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);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top