954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Binding Data to text box

Hi friends,
I have created a form with a dropdown list and a text box and i have a table named customer with fields cid and name in database.
I successfully binded the cid column to dropdown list.now my problem is i want to bind the name into the text box based on cid selected in drop down list.
Please helpme doing this.
I need it very urgent.
Thanks.

sudharani
Newbie Poster
21 posts since Sep 2009
Reputation Points: 7
Solved Threads: 1
 

Hello dear

You can use select_IndexChangeEvent Like this...

Protected Sub MyDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyDropDownList.SelectedIndexChanged
        
              Mytextbox.text =  MyDropDownList.selectedItem.text
        
    End Sub

And make sure Your Dropdownlist must have Autopostback property = true

Mark as solved if it helps you!!!

reach_yousuf
Junior Poster
195 posts since Sep 2007
Reputation Points: 12
Solved Threads: 38
 

ThanK U for your immediate reply.
But the Text Box should display the corresponding name of customer once i select the cid (Customer iD) from the drop down list.
I need coding in c#.

sudharani
Newbie Poster
21 posts since Sep 2009
Reputation Points: 7
Solved Threads: 1
 

Hi,
You might have stored the name of the customer in the database.
Just write a query to fetch the name from the table and add it to the textbox.

protected void dropdownlst_selectectchange(object s, evetntargs s)
{
string str=dropdownlist1.selecteditem.text;
string sql="select name from customer where custid="+str;
sqlcommand cmd=new sqlcommand(sql,connectionstring)
sqldatareader dr=cmd.executereader()
while(dr.read())
{
textbox1.text=dr[0].tostring();
}

}

praveenkumarm
Newbie Poster
19 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

Hi, You might have stored the name of the customer in the database. Just write a query to fetch the name from the table and add it to the textbox.

protected void dropdownlst_selectectchange(object s, evetntargs s) { string str=dropdownlist1.selecteditem.text; string sql="select name from customer where custid="+str; sqlcommand cmd=new sqlcommand(sql,connectionstring) sqldatareader dr=cmd.executereader() while(dr.read()) { textbox1.text=dr[0].tostring(); }

}


Thank U very much praveen,
Now i have another problem that i am not able to select other cid from the drop down list.If i select another "cid" from the DDL also it is not effecting.It is always displaying the first item of the list.
How to solve this.please help me.

sudharani
Newbie Poster
21 posts since Sep 2009
Reputation Points: 7
Solved Threads: 1
 

Hi,
May be you have not set the AutoPostBack property to true.

thank you,
regards

praveenkumarm
Newbie Poster
19 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

Hello Praveen,
I have given the property AutoPostBack to true.still it is giving only first item in the list.I did the code in page_load event.
Is it require to add the code in betwwen if(!page.IsPostBack) condition .
reply me soon
Thank U

sudharani
Newbie Poster
21 posts since Sep 2009
Reputation Points: 7
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You