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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 22, 2011, 10:54 PM
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