Showing posts with label Dropdown List. Show all posts
Showing posts with label Dropdown List. Show all posts

Tuesday, August 6, 2013

Bind data to Asp.net text box using dropdownlist in jquery

Title: JQuery set text box value in asp.net

Description:
In recent articles we known how to implement the  Data binding concept on data  controls like grid view,Data list,list etc.Here i would like to explain how to bind data to asp.net text box while leave the focus on Drop Down List using JQuery blur function.The blur function will fire when the previous controls has lost focus.

Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bind data to Asp.net text box using DropDownList in jquery</title>
</head>
<script type="text/javascript" src="~/jquery.min.js" ></script>
<script>
$(document).ready(function() {
$("#ddlSalesOrder").blur(function(){
var SalesOrderText = $("#ddlSalesOrder option:selected").text();
 alert(SalesOrderText);
$("#<%= txtOrderTotalAmt.ClientID %>".val(SalesOrderText); 
});
});
</script>
</head>
<body>
Amount: <asp:DropDownList ID="ddlSalesOrder" runat="server">
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>125</asp:ListItem>
<asp:ListItem>150</asp:ListItem>
<asp:ListItem>175</asp:ListItem>
<asp:ListItem>200</asp:ListItem>
</asp:DropDownList>
TotalAmount:<asp:TextBox ID="txtOrderTotalAmt" runat="server"></asp:TextBox>
</body>
</html>
As you can see there is alert to confirmation for drop down selected value will come when the blur event occurs.Whenever we are using JQuery ,we should add JQuery library reference to our application.
In the above example we have taken one drop down list and text box to display the amount order .When the amount Drop down list has lost the focus ,the total Amount will be populate automatically.

Monday, July 1, 2013

Get dropdownlist selcted value in gridview in Asp.net

Title:
how Get Drop down List selected value  in grid view using c# in asp.net
Requirement: 
.Frame Work and Sql Server
Explanation:
Here i will show how to fire selected index event of drop down in grid view.When we work with drop down list in grid view ,Most  of  the confusion about how to get the selected value of DDL.By using this event(SelectedindexChanged) we can do it.
As per requirement have to display details of selected record details in report page.By using this ,will get Drop down selected value in grid view. In the above i have fetched the drop down list selected value which in grid view.

protected void ddlorders_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow GvOrderrow= (GridViewRow)ddlorders.NamingContainer;
DropDownList ddlOrdr_name= ((DropDownList)(GvOrderrow.FindControl(“ddlorders"))).SelectedValue;
if((ddlOrdr_name.SelectedValue.ToString()) =="")
{
Response.Write("No order Exist");
}
else
{
Respose.Redirect("Report.aspx?order='"+ CurrentOrdr+"'");
}


Tuesday, April 23, 2013

How to bind data to dropdownlist with arrarylist in asp.net


In previous post we have discussed on how to bind the Data in Gridview,Disable dropdownlist .In this post i will show how to bind data to dropdownlist using array list in asp.net.Here i will populate drop down for city names.
<html>
<head>
</head>
<body>
<form runat=server>
<asp:DropDownList id="ddlcity" runat="server" />
</form>
</body>
</html>
We have to used ispostback to avoid the populating drop down while every time loading the page

protected void Page_Load(Object Sender, EventArgs E) 
{
if (!IsPostBack) {
ArrayList citynames = new ArrayList();
citynames.Add ("NewYork");
citynames.Add ("Hyderabad");
citynames.Add ("Bombay");
ddlcity.DataSource = citynames;
ddlcity.DataBind();
}
}

Wednesday, January 9, 2013

Disable dropdown list using radio button in asp.net using c#.net

In previous post we have seen how to disable the drop down list using other dropdown list.In the below we will use radio button to disable the drop down list in asp.net using c#.net.For this we have to use radiobutton checked change event
Code behind:
protected void rbcheck_CheckedChanged(object sender, EventArgs e)
{
ddltest.Enabled = false;
}

Aspx:
 <asp:RadioButton ID="rbcheck" runat="server"
 oncheckedchanged="rbcheck_CheckedChanged"  AutoPostBack="true"/>
<asp:DropDownList ID="ddltest" runat="server"
 AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
</asp:DropDownList>

Tuesday, January 8, 2013

Disable/enable Dropdownlist in asp.net using c#.net

In this post i will show how to disable a drop down in asp.net using c#.net.Here i have used two drop down lists to perform this task. Whenever  the first drop down  selected then another drop down will be disabled
Aspx:
<asp:DropDownList ID="ddloption" runat="server" onselectedindexchanged="ddloption_SelectedIndexChanged" 
       AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlcode" runat="server" 
AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
</asp:DropDownList>
Code :
protected void ddloption_SelectedIndexChanged(object sender, EventArgs e)
{
ddlcode.Enabled = false;
}
The above code is for drop down selected index event for first drop down list

Monday, January 7, 2013

Get the dropdown selectedIndex in asp.net using c#.net

In previous post we have seen how to get the drop down selected value.In this post i will show how to get the selected index value in asp.int using c#.net.Here i have used one drop down list and label to display index value.

Code:
protected void dtest_SelectedIndexChanged(object sender, EventArgs e)
{
 lbly.Text = dtest.SelectedIndex.ToString();
}
aspx:
<asp:DropDownList ID="dtest" runat="server" onselectedindexchanged="dtest_SelectedIndexChanged"
       AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Bombay</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lbly" runat="server" Text="Label"></asp:Label>


Get the dropdown selected value in asp.net using c#.net

Title:
How to get the drop down list selected value in asp.net using c#

Description:
The drop down list will display the list of items and each list of item is selectable.The best thing  of this control is ,we can bind static data or dynamic data which is to be done by using data binding concept.Now we know this control can support data binding

Example:
Some recent posts on drop down list selected value ,Jquery Drop down list validation .Now i would like to give an example on  how to get the drop down selected value in asp.net using c#.Before going to start ,we have to add one drop down list with label control which will be used to  display the drop down selected value .
Note:One more thing we need to remember i:e auto post back property set to true.If you want to see the properties of web control ,focus on control and click on F4

Aspx page:
<asp:DropDownList class="HTML" id="ddlcitytest" name="code" onselectedindexchanged="ddlcitytest_SelectedIndexChanged" runat="server"AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Bombay</asp:ListItem>
<asp:ListItem>Delhi</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblcity" runat="server" Text="Label"></asp:Label>

codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlcitytest_SelectedIndexChanged(object sender, EventArgs e)
{
//Get the selected value
lblcity.Text = ddlcitytest.SelectedValue.ToString();
}
}
In the above code the selected value has been assigned to label for display purpose.


Thursday, December 20, 2012

Jquery Dropdownlist validation in asp.net

Title: JQuery How to validate Drop Down List value  in asp.net

Description:
Recently i have worked drop down list data validation using JQuery. Now i would like to explain how to validate the data of drop down list using JQuery .In previous articles i have given an example on Jquery drop down validation,JQuery allow only numbers.Here in this post i will given script for Validate DropdownList Using JQuery
Example:
   $(document).ready(function () {
    $('#btnsubmit').click(function(){
        cntydr = $('#ddlcountry');
        if (cntydr.length == 0 || $(cntydr).val() == "") {
            alert("Please Choose Country");
        }
        });
    });
As you can see the below screen shots to know the how they will get validation  conformation on page
In the above script i have used button click event to perform the validation.So when ever we click on the submit button the validations will be done.

Monday, December 17, 2012

Java Script Dropdownlist validation in asp.net

In previous post i have given Dropdownlist validation using jquery.In this post i will show how to perform validation on drop down list using java script in asp.net.Here we have to check whether the select index value of dropdown list is zero or not.Based on that we can do validation on it .
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropdownValidation.aspx.cs" Inherits="DropdownValidation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Dropdown Validation using Jquery</title>
<script language="javascript" type="text/javascript">
function cityValidate() {
var ddlcity = document.getElementById("<%=ddlCity.ClientID %>");
if (ddlcity.selectedIndex <= 0) {
alert('please choose city');
return false;
}
else
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table><tr><td>First Name:</td><td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr>
<tr><td>Last Name:</td><td><asp:TextBox ID="txtlastname" runat="server"></asp:TextBox></td></tr>
<tr><td>Phone:</td><td>  <asp:TextBox ID="txtaddr" runat="server"></asp:TextBox></td></tr>
<tr><td>City</td><td><asp:DropDownList ID="ddlCity" runat="server">
<asp:ListItem Text="Please Select" Value=""></asp:ListItem>
<asp:ListItem Text="Hyderabad" Value="a"></asp:ListItem>
<asp:ListItem Text="Delhi" Value="b"></asp:ListItem>
<asp:ListItem Text="Bombay" Value="c"></asp:ListItem>
<asp:ListItem Text="Chennai" Value="c"></asp:ListItem>
</asp:DropDownList></td></tr></table>
<asp:Button ID="btnvalidate" runat="server" text="submit"  OnClientClick="return cityValidate()"/>
</form>
</body>
</html>
Basic Form
Alert for Dropdown validation
Recently i have seen a question regarding dropdown lists.i:e which is correct in drop down or drop-down?. Every one would provide the answer with comment on this post

Saturday, June 30, 2012

how to create dynamic dropdown list in asp.net

Here in this post i will show how to create a drop down list and add items dynamically in asp.net.We  can do this functionality in two ways one is using List  and other one is directly adding the items to drop down.The "ddllist"  is the list which will be bind to drop down list
Usign list to bind  items to dropdownlist:
DropDownList ddlcountry = new DropDownList();
List<string> ddllist = new List<string>();
ddllist.Add("India");
ddllist.Add("us");
ddllist.Add("uk");
ddlcountry.DataSource = ddllist;
dddlcountry.DataBind();
this.Controls.Add(ddlcountry);

Simple item binding to dropdownlist:
DropDownList ddlcity = new DropDownList();
ddlcity.Items.Add("Hydreabad");
ddlcity.Items.Add("Mumbai");
ddlcity.Items.Add("chennai");
this.Controls.Add(ddlcity);

Friday, May 25, 2012

BInd data to dropdownlist in gridview in asp.net

Title: How to bind data to drop down list in asp.net using c#.net

Description:
In previous posts i explained Asp.net bind data to grid view,bind data to dropdownlist,Bind drop down in MVC4.Bind grid view using LINQ. Here i will show how to binding the data to Drop down List inside of Grid View.Here the dropdownlist has place inside of grid view template Field .You can observe here i will bind data to both drop down and grid view While loading page.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Bind data to Dropdownlist in gridview in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvSalesData" AllowSorting="True" Runat="server"
AllowPaging="true" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="SalesID">
 <ItemTemplate>
 <%#Eval("SID")  %>
 </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SalesPName">
 <ItemTemplate>
<%#Eval("SalesPersonName")  %>
</ItemTemplate>
</asp:TemplateField>
 <asp:TemplateField HeaderText="Samount">
 <ItemTemplate>
<%#Eval("Samt")  %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SalesCity">
<ItemTemplate>
<asp:DropDownList ID="ddl_city" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
 </form>
</body>
</html>
Code behind:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Dropdowningridview : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["bhaskarconnection"].Tostring());

protected void Page_Load(object sender, EventArgs e)
{
If(!page.IsPostBack)
{
//Bind data to gridview
BindOrdrGrid();
//Bind data to Dropdown in gridview
BindDropdownGrid();
}
private void BindOrdrGrid()
{
 SqlDataAdapter Ordr_ad = new SqlDataAdapter("select * from Order_details", cn);
 DataSet Ordr_ds = new DataSet();
 Ordr_adp.Fill(Ordr_ds, "Order_details");
 GvSalesData.DataSource = Ordr_ds;
 GvSalesData.DataBind(); 
}
private void BindDropdownGrid()
{
cn.Open();
SqlDataAdapter Ddl_ad = new SqlDataAdapter("select * from order_city", cn);
DataSet Ddl_ds = new DataSet();
ad.Fill(Ddl_ds, "order_city");
foreach (GridViewRow row in GvSalesData.Rows)
{
DropDownList _ddlcity = (DropDownList)(GvSalesData.Rows[row.RowIndex].Cells[4].FindControl("ddl_city"));
_ddlcity.DataSource = Ddl_ds;
_ddlcity.DataValueField = "CID";
_ddlcity.DataTextField = "City_name";
_ddlcity.DataBind();
}
}

Sunday, March 25, 2012

Jquery How to Select a dropdown selected value

Title:
How to get drop down list selected value using jquery

Description:
When we start working with jquery ,we may think how and where we have to use jquery libraries.Before going to use jquery methods,we should download and add latest version of jquery plugin from jquery.com.With out plug-in we could not use any methods of jquery reference.

Example:
In previous articles i have given Jquery Dropdownlist validation,JqueryUI autocomplete textbox.Jquery Get month or year,Hide and show div using jquery ,Jquery Declare variable.In this post i will show how to get the dropdownlist selected value using jquery.Below script will show  the selected value as alert while page loading

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var ddlOrderText = $("#ddlChar option:selected").text();
alert(ddlOrderText );
var ddlOrderValue = $("#ddlChar option:selected").val();
alert(ddlOrderValue);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlChar" runat="server">
<asp:ListItem>Bhaskar</asp:ListItem>
<asp:ListItem>Aspdotnet</asp:ListItem>
<asp:ListItem>Sharepoint</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>

Bel