I always get values from the database directly to a control like this:
Code-behind:
DataTable table = GetUserInfo();
UserInfo.DataSource = table;
UserInfo.DataBind();
string FirstName = lblFirstName.Text;
string LastName = lblLastName.Text;
DateTime BecomeAMember = DateTime.Parse(lblBecomeAMember.Text);
Markup:
<asp:Label ID="lblCity" runat="server" Text='<%# Eval("FirstName") %>' />
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LastName") %>' />
<asp:Label ID="lblBecomeAMember" runat="server" Text='<%# Eval("BecomeAMember", "{0:dd MMM yyy) %>' />
There has to be a way to use the data in code-behind without putting it to a label and then use String text = label.Text;
I need the minutes and hours from BecomeAMember, and I don’t want to use another Label with the full DateTime and make it invisible. It would be nice to know how to get the other values as well.
You may use
DataTablemethods to read values directly from thetableobject.For instance,
or
Or use Select() method to search on specified field.