Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

dropdownlist (or) combobox data binding code in asp.net c#

In this post, I explained Combobox binding in single line of Code, we use one Class file, for every combobox we call that class method. you can call same for all comboboxes in your application.

Aspx.cs

using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;


namespace company
{
    public partial class valid : Telerik.WinControls.UI.RadForm
    {
        public valid()
        {
            InitializeComponent();
        }
        CommonFunctionsobjCom = new CommonFunctions();
        SqlConnectioncon = new SqlConnection(Connections.con);

        privatevoid Auction_Load(objectsender, EventArgs e)
        {
            objCom.setComboBox2("Select '0' CODE,'-- SELECT --' NAME UNION select CODE,NAME from PLAN_MASTER", "NAME", "CODE", cmbChit);
        }
}
}

CommonFunctions.cs class code


using System;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Data;
usingSystem.Data.SqlClient;

namespace SCG_CHITS
{
    public class CommonFunctions
    {
        Connections objCon = newConnections();
   public void setComboBox2(stringquery, string dataText, string dataValue, System.Windows.Forms.ComboBoxcombo)
        {
            SqlConnectioncon = new SqlConnection(Connections.con);
            SqlDataAdaptersqlDa = new SqlDataAdapter(query, con);
            DataSetdsData = new DataSet();
            sqlDa.Fill(dsData, "Details");

            combo.DataSource = dsData.Tables[0];
            combo.DisplayMember = dataText;
            combo.ValueMember = dataValue;
            combo.SelectedIndex = 0;
        }
}

}


This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

dropdownlist (or) combobox data binding code in asp.net c#

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×