I have a complete database running in SQL Server.
Next I have HTML codes for an UI which consists of a html drop down list(Note: There are css-styles for the html dropdownlist)
I'm doing development in visual studio 2008 as a result of which i can directly use asp controls and directly populate the dropdownlist. But the thing is that I have to populate the html dropdownlist from database during PageLoad without using any asp controls, so that the html styles and css scripts are not tampered.
Please suggest solutions with sample code if possible.
Dipankar BiswasPosted Jul 31, 2014, 4:49 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import namespace="System.Collections"%>
<%@ Import namespace="System.Collections.Specialized"%>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
public static string strConnectionString = ConfigurationManager.ConnectionStrings["profileconnectionstrin"].ConnectionString;
public static SqlConnection con = new SqlConnection(strConnectionString);
public static SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
string QueryString = "select * from tbl_state";
SqlConnection myConnection = new SqlConnection(strConnectionString);
SqlDataAdapter myCommand = new SqlDataAdapter(QueryString, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "tbl_state");
Select1.DataSource = ds;
Select1.DataTextField = "state";
Select1.DataValueField = "state";
Select1.DataBind();
}
}
}
Thanks
Dipankar Biswas