Author: marnovo
Subject: labele çektiğim sayıyı arttıramıyorum
Posted: 11 Eylül 2016 at 11:38
Merhaba arkadaşlar ilişkili 2 tane dropdownlist var.2 tane veri tablosundan ilişkili veri çekiyor.dropdownlistten çekmiş olduğum verileri labele yazdırıyorum.yaşadığım problem labele yazdırdığım sayıyı arttıramıyorum.tablolar ve kodlar aşagıdaki gibidir.
Subject: labele çektiğim sayıyı arttıramıyorum
Posted: 11 Eylül 2016 at 11:38
Merhaba arkadaşlar ilişkili 2 tane dropdownlist var.2 tane veri tablosundan ilişkili veri çekiyor.dropdownlistten çekmiş olduğum verileri labele yazdırıyorum.yaşadığım problem labele yazdırdığım sayıyı arttıramıyorum.tablolar ve kodlar aşagıdaki gibidir.
urunler tablosu
urunid
urunadi
urunrakam
sira tablosu
siraid
urunid
sirano
urunler tablosu
1 bilgisayar 155
2 yazıcı 186
3 notebook 195
sira tablosu
1 2(yazıcı) 001
2 3(notebook) 001
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=test;Integrated Security=True");
string urunid = "";
int sayi;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_DropDownList1();
}
}
public void Bind_DropDownList1()
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from urunler", conn);
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.Items.Clear();
DropDownList1.DataTextField = "urunadi";
DropDownList1.DataValueField = "urunid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("Seçiniz", "0"));
conn.Close();
}
public void Bind_DropDownList2()
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from sira where urunid='" + DropDownList1.SelectedValue + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
DropDownList2.DataSource = dr;
DropDownList2.Items.Clear();
DropDownList2.DataTextField = "sirano";
DropDownList2.DataValueField = "siraid";
DropDownList2.DataBind();
conn.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Bind_DropDownList2();
SqlConnection baglanti = new SqlConnection("Server=localhost;Database=test;Trusted_Connection=True;");
SqlCommand komut = new SqlCommand();
baglanti.Open();
komut.Connection = baglanti;
komut.CommandText = ("SELECT * from urunler");
komut.ExecuteNonQuery();
SqlDataReader dr = komut.ExecuteReader();
if (dr.Read())
{
Label1.Text = dr["urunrakam"].ToString();
Label2.Text = DropDownList2.SelectedItem.Text;
}
baglanti.Dispose();
baglanti.Close();
sayi = Convert.ToInt32(Label2.Text);
Label2.Text = sayi.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
sayi += 1;
Label2.Text = sayi.ToString();
}
}