Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts
Thursday, 23 July 2015
Tuesday, 9 June 2015
Posted by Unknown on 02:50
with No comments so far
Introduction:
In this article I will explain how to fill or filter a gridview
based on dropdown selected value in asp.net using c#, vb.net.
In his article I will filter the gridview data according to dropdown selection.
First of all I will bind the dropdown with data from database and then
gridview. After binding the data from database I will filter the data based on
dropdown selection.
Friday, 5 June 2015
Posted by Unknown on 03:41
with No comments so far
Introduction:
In this article I will explain how to set dropdownlist selected value on page load or code
behind in asp.net (c#, vb.net). In dropdownlist we can set selected item by
value or text using FindByValue and FindByText properties.
We have two different methods to
set dropdownlist selected value.
Method 1: Set Dropdownlist
Selected Value Based on value
using FindByValue property we can set dropdownlist
selected value
ddlusers.Items.FindByValue("4").Selected
= true;
Method 2: Set Dropdownlist
Selected value based on Text
using FindByText property we can set dropdownlist
selected value
ddlusers.Items.FindByText("Sales").Selected
= true;
Source Code for sample
Application:
Design
your page as given below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>set dropdownlist default value in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<fieldset style="width:250px">
<legend><strong>Set Default Value OF dropdown </strong></legend>
<div>
<asp:DropDownList ID="ddlDept"
runat="server">
<asp:ListItem Value="1">HR</asp:ListItem>
<asp:ListItem Value="2">Marketing</asp:ListItem>
<asp:ListItem Value="3">Production</asp:ListItem>
<asp:ListItem Value="4">Sales</asp:ListItem>
<asp:ListItem Value="5">Inventory</asp:ListItem>
</asp:DropDownList>
</div></fieldset>
</form>
</body>
</html>
ASP.Net code Behind file code:
C# Code
write the code like as shown below
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// set dropdownlist selected based on text
ddlusers.Items.FindByText("Sales").Selected
= true;
}
}
VB.NET Code
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
' set dropdownlist selected based on text
ddlusers.Items.FindByText("Sales").Selected
= True
End If
End Sub
End Class
Monday, 30 March 2015
Sunday, 8 March 2015
Thursday, 5 March 2015
Thursday, 26 February 2015
Posted by Unknown on 01:20
with No comments so far
In asp.net we can clear dropdownlist using the server side code i.e. DropDownList1.ClearSelection() method. We can do this at client side using jQuery. Jquery is fast and light as compare to server side code. So it is good to use jquery rather than write a code for this purpose. There are a number of methods to reset dropdown list back to default state.
Tuesday, 17 February 2015
Posted by Unknown on 03:04
with No comments so far
Introduction:

Suppose if Department Name is “HRM” then it got disable.
In this article, I have explained how to dynamically Fill Dropdown List from SQL
Tuesday, 12 November 2013
Posted by Unknown on 01:55
with No comments so far
Introduction:
In this article you
will come to know how to bind dropdownlist in asp.net with database.
Implementation:
In the desgin (.aspx)
page desgin the struture as below: Add dropdown control on the webpage.
<asp:DropDownList ID="ddlState" runat="server">
</asp:DropDownList>
Write code in code
behind file to Bind Dropdown:
C#.Net code
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
SqlConnection con
= new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropdown();
}
}
private void BindDropdown()
{
SqlDataAdapter adp = new SqlDataAdapter("select * from Tb_STATE", con);
DataTable dt = new DataTable();
adp.Fill(dt);
ddlState.DataSource = dt;
ddlState.DataTextField = "STATE";
ddlState.DataValueField = "ID";
ddlState.DataBind();
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
adp.Dispose();
}
VB.Net Code
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConStr").ToString())
Private Sub BindDropdown()
Dim adp As New SqlDataAdapter("select * from Tb_STATE", con)
Dim dt As New DataTable()
adp.Fill(dt)
ddlState.DataSource = dt
ddlState.DataTextField = "STATE"
ddlState.DataValueField = "ID"
ddlState.DataBind()
ddlState.Items.Insert(0, New ListItem("--Select--", "0"))
con.Close()
adp.Dispose()
End Sub
Protected Sub Page_Load(sender As Object,
e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindDropdown()
End If
End Sub
Subscribe to:
Posts (Atom)