LLBLGenProDataSource For DropdownList

Posts   
 
    
shbshams
User
Posts: 1
Joined: 01-Dec-2006
# Posted on: 01-Dec-2006 00:26:51   

I have a GridView with an edit item as dropdownlist:

<asp:TemplateField HeaderText="State" SortExpression="StateCode">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblState"  Text='<%# DataBinder.Eval(Container.DataItem, "StateCode") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlState" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "StateID") %>' DataSourceID="LLBLGenProDataSourceState" DataTextField="StateName" DataValueField="StateID" runat="server">
                            [b]<asp:ListItem Text="Select State..." Value="0"></asp:ListItem>[/b]
                        </asp:DropDownList>
                    </EditItemTemplate>
</asp:TemplateField>

My LLBLGenProDataSource is like this:

<cc1:LLBLGenProDataSource
        ID="LLBLGenProDataSourceState"
        DataContainerType="EntityCollection"
        EntityCollectionTypeName="DHHS.Core.DAL.CollectionClasses.StateCollection, DHHS.Core.DAL" 
        runat="server">
    </cc1:LLBLGenProDataSource>

My problem is in the state dropdown first row "Select State..." is not coming.

Any suggestions?

Thanks in advance .

Shabab

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 01-Dec-2006 03:35:55   

Databinding will override any static values you set. What you can do is to use the following to insert the value when the row is being edited. This is for a Grid named GridView1.


                protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == GridView1.EditIndex)
            {
                //e.Row.DataBind();
                DropDownList ddl = (DropDownList)e.Row.FindControl("ddlState");
                ddl.Items.Insert(0, new ListItem("Select Name", "Select Name"));
            }
        }
        }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Dec-2006 10:37:45   

ASP.NET related issue: an ASP.NET dropdownlist has a property which allows you to specify th ADD databound elements to the already existing elements. That property can be set in the HTML using the AppendDataBoundItems attribute.

Frans Bouma | Lead developer LLBLGen Pro