RSS

Tag Archives: DropDownList

Add Default Item to DropDownList Dynamically

How to add a default item as ‘N/A’ to drop down list and set selected?

gnList.DataSourceID = "GNDS";
gnList.DataTextField = "Name";
gnList.DataValueField = "Id";
gnList.DataBind();
gnList.Items.Insert(0, new ListItem("N/A", "0"));

Another way

gnList.Items.Add(new ListItem("N/A", "0"));
gnList.DataSourceID = "GNDS";
gnList.DataTextField = "Name";
gnList.DataValueField = "Id";
gnList.DataBind();
gnList.Items.FindByValue("0").Selected = true;
Advertisements
 
Leave a comment

Posted by on March 21, 2015 in ASP.Net

 

Tags:

Static DropDownList in GridView

Displaying a DropDownList column in GridView and setting the selected item.

<asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:DropDownList  ID="DropDownList1" runat="server"  SelectedValue='<%# Bind("Status") %>' autocomplete="off" Width="150">
                                    <asp:ListItem Value="1">Enable</asp:ListItem>
                                    <asp:ListItem Value="2">Disable</asp:ListItem>
                                    <asp:ListItem Value="3">Delete</asp:ListItem>
                                </asp:DropDownList>  
                            </ItemTemplate>
                        </asp:TemplateField>
 
Leave a comment

Posted by on March 20, 2015 in ASP.Net

 

Tags: