Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi how can i bind field from table to label?
Posted
Comments
DamithSL 28-May-14 5:03am    
you can set the text property of the label by any value you want. please explain your requirement and what you tried so far.
Nirav Prabtani 28-May-14 5:18am    
Where is your label??
Mohammad Hasanpoor 28-May-14 5:38am    
i have table that it has two field. "name" and "mark" fields.
i want select name in combobox then mark of that name appear in label.
Mohammad Hasanpoor 28-May-14 6:22am    
please answer. i need.

try this..:)

C#
//Put this code in Combobox selected index change event

      DataTable dt = new DataTable();
      using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString))
      {
          using (SqlCommand cmd = new SqlCommand("select Mark from TableName where Name="+ ComboBox.SelectedValue, con))
          {
              con.Open();
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              da.Fill(dt);

              lblMark.Text = Convert.ToString(dt.Rows["Mark"]);

              con.Close();
              con.Dispose();
              cmd.Dispose();
          }
      }
 
Share this answer
 
Comments
Mohammad Hasanpoor 28-May-14 15:52pm    
sorry but it does't work.
(it is c# code) i want vb.net code
Its work for me but this label was inside my Gridview

Hope its work for you also

<asp:label id="Name1" runat="server" text="<%#DataBinder.Eval(Container.DataItem, " column_name")%&gt;"="" xmlns:asp="#unknown">
 
Share this answer
 
Comments
Mohammad Hasanpoor 28-May-14 5:06am    
sorry but i work in vb.net.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900