Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> add default value to dropdownlist in gridview
 

Pages: 1
LLBLGen Pro Runtime Framework
add default value to dropdownlist in gridview
Page:1/1 

  Print all messages in this thread  
Poster Message
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 05-Jul-2006 09:32:51.  
I am binding my ddl in an asp.net gridview (VS 2005)

Code:

<ItemTemplate>
            <asp:DropDownList ID="ddlCertificateTypeID" Selectedvalue='<%# Eval("CertificateTypeID")%>' runat="server" DataSource='<%# CertificateTypes() %>'
             DataTextField="CertificateType" DataValueField="CertificateTypeID" Enabled="false" >
            </asp:DropDownList>


.
.
.

Public ReadOnly Property CertificateTypes() As CertificateTypeCollection
    '
    ' All Certificate Types
    '
    Get
     Dim certColl As CertificateTypeCollection
     certColl = CertificateTypeEntity.GetCertificateTypeCollection

     Return certColl

    End Get

End Property


I now want to add a "[No value selected yet]" to the top of the dropdownlist that corresponds to null in the backend database.

I have done this before, when I am dealing with just one dropdown on a form.
Code:


Const COMBO_NULL As String = "[No value selected yet]"

...

ddlStatus1.DataSource = PsStatusEntity.GetStatusCollection
ddlStatus1.DataValueField = PsStatusFieldIndex.StatusId.ToString
ddlStatus1.DataTextField = PsStatusFieldIndex.StatusDescr.ToString
ddlStatus1.DataBind()
ddlStatus1.Items.Insert(0, COMBO_NULL)



Can anyone help me do this "for the multiple entries in the datagrid?
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38092 posts
# Posted on: 05-Jul-2006 11:55:02.  
From my bare head I'd say add an option tag to the HTML.

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Jez
User



Location:
UK
Joined on:
01-May-2006 00:54:18
Posted:
198 posts
# Posted on: 05-Jul-2006 12:58:10.  
You could bind to the RowDataBound event for the gridview and programatically manipulate the dropdownlist for that particular row.

You should be able to do something like:

Code:

protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)    
    {
        //Gets first control in the first cell.
        DropDownList myDropDown = (DropDownList)e.Row.Cells[0].Controls[0];
        myDropDown.Items.Insert(0, "[No items selected"]);
    }
}


It should be straightforward to convert the above to VB. I haven't actually tested this so it may need some tweaks Regular Smiley
  Top
like2175
User



Location:
Camberley, United Kingdom
Joined on:
27-Mar-2006 16:16:06
Posted:
83 posts
# Posted on: 21-Nov-2007 09:45:15.  
Better solution:

You can add items to your ddl by creating a <asp:ListItem> entry as follows:

Code:
<asp:DropDownList ID="cboRepGroup" runat="server" AutoPostBack="True" DataSource='<%#ReportGroups%>'
     DataTextField="GroupName" DataValueField="AppReportGroupID" AppendDataBoundItems="true">
     <asp:ListItem Text="--Select--" Value=""></asp:ListItem>
    </asp:DropDownList>


Make sure you
Quote:
AppendDataBoundItems="true"


Simple!
Wink


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.