DropDown list not displaying--Urgent!!

G

Guest

Hi
Am doing a web app which has a datagrid with template columns. One of the
columns has dropdowns for each row. I also have the EditCommandColumn. The
problem am facing is I just see the last value of the dataset for the
dropdowns(in the non-edit mode). and moreover its just showing it as a label
instead of a dropdown. But once I click the Edit button, its displaying the
dropdowns with all dataset values. Here is the code for my ItemDataBound
event handler

protected void dgDetails_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.EditItem)
{
DropDownList list = (DropDownList)e.Item.FindControl("ddlOrder");
list.DataSource = dsOrder;
list.DataTextField = dsOrder.Tables[0].Columns[0].ColumnName;
list.DataValueField = dsOrder.Tables[0].Columns[0].ColumnName;
list.DataBind();
}
}

and this is the html
<ASP:TEMPLATECOLUMN HeaderText="Order">
<HEADERSTYLE FONT-BOLD="True" BACKCOLOR="#EDEAE7"></HEADERSTYLE>
<ITEMTEMPLATE>
<%# DataBinder.Eval(Container, "DataItem.DisplayOrder") %>
</ITEMTEMPLATE>
<EDITITEMTEMPLATE>
<ASP:DROPDOWNLIST ID="ddlOrder" runat="server" CssClass="label242"
Height="20" Width="40" Font-Size="12px"
DataValueField="DisplayOrder" DataTextField="DisplayOrder"
DataSource='<%# dsOrder %>' SelectedIndex='<%#
GetSelectedIndex(DataBinder.Eval(Container.DataItem,"DisplayOrder").ToString()) %>'
AutoPostBack="True" >
</ASP:DROPDOWNLIST>
</EDITITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>

What do I have to do so that the dropdowns are shown when the page loads the
first time too.
Can anyone help me with it please?

Thanks
 
G

Guest

thanks JV... it was helpful. But I have another issue here. Am populating the
dropdowns right, and when I edit it,its going to update in the database,
which causes the updated values to be displayed for the dropdowns. But I want
a set of specific values (its 1 thru 5) to be displayed for them instead of
the updated set of values. Do you have any thoughts on how to do this?

thanks
 

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

Top