943,675 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 1799
  • ASP.NET RSS
Sep 5th, 2009
0

Binding Data to text box

Expand Post »
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.
Reputation Points: 7
Solved Threads: 1
Newbie Poster
sudharani is offline Offline
21 posts
since Sep 2009
Sep 7th, 2009
0

Re: Binding Data to text box

Hello dear

You can use select_IndexChangeEvent Like this...
ASP.NET Syntax (Toggle Plain Text)
  1. Protected Sub MyDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyDropDownList.SelectedIndexChanged
  2.  
  3. Mytextbox.text = MyDropDownList.selectedItem.text
  4.  
  5. End Sub
And make sure Your Dropdownlist must have Autopostback property = true

Mark as solved if it helps you!!!
Reputation Points: 12
Solved Threads: 38
Junior Poster
reach_yousuf is offline Offline
194 posts
since Sep 2007
Sep 7th, 2009
0

Re: Binding Data to text box

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#.
Reputation Points: 7
Solved Threads: 1
Newbie Poster
sudharani is offline Offline
21 posts
since Sep 2009
Sep 8th, 2009
0

Re: Binding Data to text box

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();
}

}
Reputation Points: 10
Solved Threads: 2
Newbie Poster
praveenkumarm is offline Offline
19 posts
since Aug 2009
Sep 8th, 2009
0

Re: Binding Data to text box

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.
Reputation Points: 7
Solved Threads: 1
Newbie Poster
sudharani is offline Offline
21 posts
since Sep 2009
Sep 8th, 2009
0

Re: Binding Data to text box

Hi,
May be you have not set the AutoPostBack property to true.
<aspropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlst_selectectchange">
</aspropDownList>

thank you,
regards
Reputation Points: 10
Solved Threads: 2
Newbie Poster
praveenkumarm is offline Offline
19 posts
since Aug 2009
Sep 9th, 2009
0

Re: Binding Data to text box

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
Reputation Points: 7
Solved Threads: 1
Newbie Poster
sudharani is offline Offline
21 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: deploy unsigned windows forms control (activex) for intranet use
Next Thread in ASP.NET Forum Timeline: Smo.StoredProcedure Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC