Customer Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=Master;Trusted_Connection=True");
SqlCommand cmd;
string str;
int count;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropdown();
}
}
void FillDropdown()
{
cb_DropDownList1.Items.Add("choose");
con.Open();
str = "select * from customerdetails";
cmd = new SqlCommand(str, con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
cb_DropDownList1.Items.Add(reader["Companyid"].ToString());
}
reader.Close();
con.Close();
}
protected void btn_new_Click(object sender, EventArgs e)
{
str = "select count(*) from customerdetails";
cmd = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(cmd.ExecuteScalar()) + 1;
cb_DropDownList1.Items.Add("C0000" + count);
con.Close();
}
protected void btn_save_Click(object sender, EventArgs e)
{
con.Open();
str = "insert into customerdetails values (' " + cb_DropDownList1.SelectedItem.Text + "',' " + txt_comname.Text + "',' " + txt_address.Text + "',' " + cb_area.Text + "',' " + txt_city.Text + "',' " + txt_state.Text + "', " + txt_phone.Text + ", " + txt_pincode.Text + ", " + txt_mobileno.Text + ", '" + txt_email.Text + "',' " + txt_contactperson.Text + "', ' " + cb_status.Text + "')";
cmd = new SqlCommand(str, con);
Response.Write("Record Inserted successfully");
cmd.ExecuteNonQuery();
con.Close();
}
protected void btn_update_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update customerdetails phone ' " + txt_phone.Text + "' where Companyid =' " + cb_DropDownList1.SelectedItem.Text + "'", con);
cmd.ExecuteNonQuery();
Response.Write("record updated successfully");
SqlCommand cmd1 = new SqlCommand("select * from customerdetails", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
adp.Fill(ds);
con.Close();
}
protected void btn_delete_Click(object sender, EventArgs e)
{
}
protected void cb_DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
str = "select * from customerdetails where Companyid like ' " + cb_DropDownList1.SelectedItem.Text + "% '";
cmd = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "customerdetails");
con.Close();
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//cb_DropDownList1.Text = "";
txt_comname.Text = "";
txt_address.Text = "";
cb_area.Text = "";
txt_city.Text = "";
txt_state.Text = "";
txt_phone.Text = "";
txt_pincode.Text = "";
txt_mobileno.Text = "";
txt_email.Text = "";
txt_contactperson.Text = "";
cb_status.Text ="";
}
}
when i click the dropdown in comapny id the corresponding id details will not be displayed in detail view.kindly please help me.help me please urgent