Hi dear,..
How to retive the data using detail view in Dropdown List Visual Studio 2005 using Sql Server
Thanks&Regs
Narasiman
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 22, 2011, 5:54 PM EST
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Detailview_Dropdown._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Detailview_Dropdown
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropdown();
}
}
void FillDropdown()
{
SqlConnection conn = new SqlConnection(connStr);
DropDownList1.Items.Add("Choose");
conn.Open();
str = "select * from Vendor";
cmd = new SqlCommand(str, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
DropDownList1.Items.Add(reader["VendorFName"].ToString());
}
reader.Close();
conn.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from Vendor where VendorFName like '" + DropDownList1.SelectedItem.Text + "%'";
cmd = new SqlCommand(str, conn);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "Vendor");
conn.Close();
DetailsView1.DataSource = ds;
DetailsView1.DataMember = "Vendor";
DetailsView1.DataBind();
}
}
}
Thanks
If this post helps you mark it as answer