how can bind the value of datasource into textbox by coding in

Posted by Bhuwan87rawat under ASP.NET on 9/23/2012 | Points: 10 | Views : 2443 | Status : [Member] | Replies : 2
hello sir
in my application i want to bind a datasource in textbox.....
in my application i take a textbox , in textbox show all pincode (pin code store in ds (like data source)
this is possible in to bind datasource in textbox



Posted by: Dharanidhar on: 9/23/2012 [Member] Starter | Points: 25

Hi bhuwan,
For Example,Here Lets take an XML file as your Datasource.
ASPX Page:-
<asp:TextBox ID="ttt" runat="server"></asp:TextBox>

Then create an xml file as follows:-
XML file


Then In code Behind(.cs),Use
namespace Write below code:-

 XmlDocument doc = new XmlDocument();

XmlNode root = doc.DocumentElement;
ttt.Text = root.SelectSingleNode("Pin").ChildNodes[0].Value.ToString();

In above code,We are creating an object for 'xmlDocument' which is present in system.xml.This 'XmlDocument' is used to load all the xml data.In the next step We are loading the xml data from an xml file(Here XMLFile.xml).
In the Next step.'DocumentElement' gets the Root element for the Document and assigning the root value to 'XmlNode' object(Here 'XmlNode' Represents root Node).In nextstep we are using 'xmlnode' object to select a single Node and its ChildNode value.At last We are assigning this value to Textbox.(Here root contains <Address> node and selecting <pin> node and printing the text Present in <pin> node in the TextBox).

Thanqs & Regards

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

Posted by: Kianurieves on: 9/24/2012 [Member] Starter | Points: 25

Use DataGridView1_SelectionChanged event and inside get the current row using bindingSource Position prop. After that assign datarow cell value to each textbox. Datarow dr = ((DataTable)bindingSource.DataSource).Rows[bindingSource.Position]; textbox1.Text = dr[0].ToString(); textBox2.Text = dr[1].ToString();

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

Login to post response