update textbox based on value selected in combobox?

Posted by Sudheep.grandhe under C# on 11/23/2011 | Points: 10 | Views : 15671 | Status : [Member] | Replies : 12
Hi,


I have combox with 4 values Apple,Oranges,Kiwi and Bread on windows form. I want to update a price textbox on same form based on value selected in combobox. so if Apple got selected in combobox, price textbox should show 3.99,if kiwi in combobox than value in text box is 2.99 and so on. if i selected a value as apple it has to show all the remainging textboxes with data.please do the needful

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/23/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Do you want to update the price textbox.If so you can write code for this in the SelectedIndexChanged event of the combo box like

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{
textBox1.Text = comboBox1.SelectedItem.ToString();
}


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it's working but it wont show the value.instead it shows like this 'System.Data.DataRowView'.how can i resolve this error.please do the needful.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/23/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Provide your code

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Chechi,

Here is my code.please find it.

private void cmb_companyname_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select * from tbl_report2,tbl_report1", con);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd.Parameters.AddWithValue("@invoicno", txt_invoiceno.Text);
txt_perprice.Text = cmb_companyname.SelectedItem.ToString();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
txt_customeraddress .Text = dt.Rows.ToString();
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

try this

txt_customeraddress .Text =Convert.ToString( dt.RowsRows[0]["fieldName"])


Happy Programming!!
Rohi

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it will not work

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/23/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

try this
if(dt.Rows.Count >0)
{
txt_customeraddress.Text=dt.Rows[0]["<yourfieldname>"].ToString();
}

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vanajasethu on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
try this


textbox1.Text = ((DataRowView)comboBox1.SelectedItem).Row["columnname"].ToString();

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: chaudharysunny1989-22042 on: 5/4/2013 [Member] Starter | Points: 25

Up
0
Down
hi sir i want to do like when select a value(emp_name) from autocomplete combobox then there corresponding value(emp_address) fill in text box auto matic sir pls help me

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/5/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Guys all your answers are not correct

The first thing that should be asked in this case is to see the code use to bind the dropdown

The second thing would be simple. Binding a dropdown is very easy thing



Thank you for posting at Dotnetfunda
[Administrator]

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetguy on: 5/7/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Sudeep,

First bind dropdown (combobox) with list of items Apple,Oranges,Kiwi and Bread from database in form load
hope (Apple,Oranges,Kiwi and Bread) this data is fetching from database.

OnselectedIndex changed event fired pass dropdown selected value to database query and get the required details
from your code I observed some problems

1)your are not filtering data by selected Item value
2)you should not use dt.Rows.ToString() directly instead of that you should use

if(dt.Rows.Count >0)
{
txt_customeraddress.Text= Convert.ToString(dt.Rows[0]["fieldname"]);
}

If you have further problems feel free to ask me


Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 5/7/2013 [Member] Starter | Points: 25

Up
0
Down
I think,

You have not mentioned DataTextField and DataValueField for cmb_companyname control before cmb_companyname.DataBind() ....

http://hashtagakash.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response