Click here to Skip to main content
15,916,042 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to set the "Select" HardCode first value dropdown in grid view.
  <asp:TemplateField HeaderText="Professional Role">
                                            <itemtemplate>
                                                <asp:DropDownList runat="server" ID="ddlProfRole" width="87%" DataValueField="ProfRoleCode" DataSourceID="SqlDataSource2" DataTextField="ProfRoleDescription">
                                            </itemtemplate>
                                            <itemstyle horizontalalign="Center" width="25%" />
                                       

<asp:SqlDataSource ID="SqlDataSource2" runat="server"   
    ConnectionString="<%$ConnectionStrings:MPP%>"
    SelectCommand="select ProfRoleCode,ProfRoleDescription,Designcode,DeptID from mppProfRoleMapping order by ProfRoleCode">

Regards,
Ganesh.S
Posted
Updated 4-Jul-11 7:04am
v2

Use the property AppendDataBoundItems
<asp:dropdownlist runat="server" id="ddlProfRole" width="87%" datavaluefield="ProfRoleCode" datasourceid="SqlDataSource2" datatextfield="ProfRoleDescription" appenddatabounditems="true" xmlns:asp="#unknown">
    <asp:listitem text="ALL" value="" />   
</asp:dropdownlist>

Further reading
ListControl.AppendDataBoundItems Property in ASP.NET[^]
 
Share this answer
 
Comments
gani7787 5-Jul-11 3:35am    
Hi,
it will not support in the Gridview item template. pls. give us some other solution.getting error.Element list item is not supported.

see my code
-----------
<asp:TemplateField HeaderText="Professional Role">
<itemtemplate>
<asp:DropDownList runat="server" ID="ddlProfRole" width="87%" DataValueField="ProfRoleCode" DataSourceID="SqlDataSource2" DataTextField="ProfRoleDescription"
AppendDataBoundItems="true" xmlns:asp="#unknown">
<asp:ListItem Text="(Select a Role)" Value="" />


<itemstyle horizontalalign="Center" width="25%">
Hello,

add this before closing ur dropdownlistcontrol
<asp:ListItem Text="Select" Value="-1" ></asp:ListItem>

hoping it will help you

thanks
sanjeev
 
Share this answer
 
Comments
gani7787 4-Jul-11 8:58am    
I have added. But, still not displaying "select" in dropdown while pageload.

see the below code

<asp:GridView ID="GridView1" runat="server" align="center" AllowPaging="True" DataKeyNames="Priority"
AutoGenerateColumns="False" class="tabulardata" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="100%" OnRowCommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound">
<columns>
<asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="2%">
<itemtemplate>
<asp:Label ID="Sno" runat="server">

<itemstyle horizontalalign="Center">

<asp:BoundField HeaderText="Project Number" Visible="true" DataField="Priority"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="Priority">
<itemstyle horizontalalign="Center" width="3%">

<asp:BoundField HeaderText="Current Designation" Visible="true" DataField="Designation"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="Designation">
<itemstyle horizontalalign="Center" width="25%">

<asp:TemplateField HeaderText="Professional Role">
<itemtemplate>
<asp:DropDownList runat="server" ID="ddlProfRole" width="87%" DataValueField="ProfRoleCode" DataSourceID="SqlDataSource2" DataTextField="ProfRoleDescription">
<asp:ListItem Text="Select" Value="-1">

<itemstyle horizontalalign="Center" width="25%">

<asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:HyperLink ID="hyperlink1" runat="server" Height="20"
ImageUrl="~/images/Access.gif"
Width="20" />

<itemstyle horizontalalign="Center" width="2%">


<alternatingrowstyle backcolor="#FFF5F5">


pls. help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900