Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 02, 2012 02:11 PM by christiandev
Member
258 Points
175 Posts
May 02, 2012 09:11 AM|LINK
HI
i want ot know that is there is any soluion i which i bind data to text box or lable from database
its easy to bind data with controls like grid view repeater etc but i want to bind data with text box , lable
Participant
1837 Points
531 Posts
May 02, 2012 09:13 AM|LINK
TextBox1.Text=set.Tables[0].Rows[0]["ColName"].ToString(); hope will help u.
483 Points
179 Posts
May 02, 2012 12:51 PM|LINK
TextBox1.Text=ds.Tables[0].Rows[i]["ColName"].ToString(); LabelID.Text=ds.Tables[0].Rows[i]["ColName"].ToString();
37 Points
40 Posts
May 02, 2012 12:56 PM|LINK
It is at Server Side code or ClientSide Code
Star
8597 Points
1841 Posts
May 02, 2012 01:00 PM|LINK
How are you retrieving the data? ADO.NET classes, LINQ2SQL, EF?
or are you using the 'smart binding' tools of the grid view etc and looking for something similar in textboxes or labels?
May 02, 2012 01:10 PM|LINK
i m using ADO.Net
10980 Points
1691 Posts
May 02, 2012 01:11 PM|LINK
Hello,
Textbox is not a databound control.
Still you can achieve this by putting you text box in repeart and bind value to text box.
Follow this discussion
http://forums.asp.net/t/1139913.aspx
and if you want to populate textboxes and label . you can do this in code behind
like in page_load event
e.g.
lblName.Text = datatable[0].Rows[0]["Name"];
txtName.Text = datatable[0].Rows[0]["Name"];
10672 Points
2426 Posts
May 02, 2012 01:15 PM|LINK
Unseendreamzzz its easy to bind data with controls like grid view repeater etc
Same way you can populate TextBox also. See this sample code
void filltextBox() { string constr = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString; string qry1 = "SELECT emp_Name FROM emps WHERE emp_Id =1"; SqlConnection conn = new SqlConnection(constr); conn.Open(); SqlCommand cmd1 = new SqlCommand(qry1, conn); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); da1.Fill(dt1); TextBox2.Text = dt1.Rows[0][0].ToString(); conn.Close(); }
May 02, 2012 02:11 PM|LINK
If your looking to bind the controls to an object/model, then create your class
class person { name surname age }
then using ado.net, you could build your object using a datareader (http://msdn.microsoft.com/en-us/library/haa3afyz.aspx) and return your object... public person GetPerson(int id) { ....data reader code to build person object.... }
in your code-behind, you would have person myPerson = GetPerson(1); lblName.text = myPerson.Name; etc.
this way, if you decide to move from ASO.NET to LINQ2SQL for example, you only need to change the GetPerson method implementation.
Unseendreamz...
Member
258 Points
175 Posts
databinding
May 02, 2012 09:11 AM|LINK
HI
i want ot know that is there is any soluion i which i bind data to text box or lable from database
its easy to bind data with controls like grid view repeater etc but i want to bind data with text box , lable
shivalthakur
Participant
1837 Points
531 Posts
Re: databinding
May 02, 2012 09:13 AM|LINK
Response.Write("Success");
Best Of Luck
Shival Thakur
ziaulrahman
Member
483 Points
179 Posts
Re: databinding
May 02, 2012 12:51 PM|LINK
Mark answer if it helps.
kdadasaheb12...
Member
37 Points
40 Posts
Re: databinding
May 02, 2012 12:56 PM|LINK
It is at Server Side code or ClientSide Code
christiandev
Star
8597 Points
1841 Posts
Re: databinding
May 02, 2012 01:00 PM|LINK
How are you retrieving the data? ADO.NET classes, LINQ2SQL, EF?
or are you using the 'smart binding' tools of the grid view etc and looking for something similar in textboxes or labels?
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
Unseendreamz...
Member
258 Points
175 Posts
Re: databinding
May 02, 2012 01:10 PM|LINK
i m using ADO.Net
Nasser Malik
Star
10980 Points
1691 Posts
Re: databinding
May 02, 2012 01:11 PM|LINK
Hello,
Textbox is not a databound control.
Still you can achieve this by putting you text box in repeart and bind value to text box.
Follow this discussion
http://forums.asp.net/t/1139913.aspx
and if you want to populate textboxes and label . you can do this in code behind
like in page_load event
e.g.
lblName.Text = datatable[0].Rows[0]["Name"];
txtName.Text = datatable[0].Rows[0]["Name"];
Skype: maleknasser1
basheerkal
Star
10672 Points
2426 Posts
Re: databinding
May 02, 2012 01:15 PM|LINK
Same way you can populate TextBox also. See this sample code
void filltextBox() { string constr = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString; string qry1 = "SELECT emp_Name FROM emps WHERE emp_Id =1"; SqlConnection conn = new SqlConnection(constr); conn.Open(); SqlCommand cmd1 = new SqlCommand(qry1, conn); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); da1.Fill(dt1); TextBox2.Text = dt1.Rows[0][0].ToString(); conn.Close(); }(Talk less..Work more)
christiandev
Star
8597 Points
1841 Posts
Re: databinding
May 02, 2012 02:11 PM|LINK
If your looking to bind the controls to an object/model, then create your class
class person
{
name
surname
age
}
then using ado.net, you could build your object using a datareader (http://msdn.microsoft.com/en-us/library/haa3afyz.aspx) and return your object...
public person GetPerson(int id)
{
....data reader code to build person object....
}
in your code-behind, you would have
person myPerson = GetPerson(1);
lblName.text = myPerson.Name;
etc.
this way, if you decide to move from ASO.NET to LINQ2SQL for example, you only need to change the GetPerson method implementation.
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)