18 Feb 2014

add dataset items to listbox in c# asp.net (or) how to bind data in listbox in asp.net c#

In this post , I explained how to bind data set values to list box.  I have used  stored procedures in this article.  Here  lbFunctions is my list box ID.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace Company
{
    public partial class NamedFunctions : Telerik.WinControls.UI.RadForm
    {
  private void getNames()
        {
            try
            {
                SqlConnection con = new SqlConnection(”connectionString”);
                da = new SqlDataAdapter("Your_StoredProcedure_Name ", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                dsDetails = new DataSet();
                da.Fill(dsDetails, "Details");

                for (int i = 0; i < dsDetails.Tables[0].Rows.Count; i++)
                {
                    lbFunctions.Items.Add(dsDetails.Tables[0].Rows[i]["TABLE_FIELD_NAME"]);
                }
            }
            catch (Exception ex)
            {
            }
        }
 }
}


No comments:

Post a Comment