使用<asp:GridView></asp:GridView>我试图显示数据库表的列.我想获取表的主键但显然不想显示它.我怎样才能做到这一点?
这是我的GridView
<asp:GridView ID="MyGrid" runat="server" BorderColor="#0066FF" AllowPaging="false" PageSize="5" AllowSorting="true" AutoGenerateColumns="false"
AutoGenerateEditButton="true" OnRowEditing="MyGrid_RowEditing" AutoGenerateDeleteButton="true" OnRowDeleting="MyGrid_RowDeleting"
OnRowDataBound="MyGrid_RowDataBound" EmptyDataText="No Value" BorderWidth="0px" BorderStyle="Solid">
<Columns>
<asp:BoundField DataField="PrimaryKey" HeaderText="UserId"/>
<asp:BoundField DataField="Column1" HeaderText="Column1" />
<asp:BoundField DataField="Column2" HeaderText="Column2" />
<asp:BoundField DataField="Column3" HeaderText="Column3" />
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
我也试图visible=false隐藏主键,它隐藏了主键,但也没有获取它的值,我想要这个值.
希望我的问题很明确.
我在写一个相当大的web应用asp.net/c#与MSSQL 2008 r2服务数据库.该程序需要转换date/time(ISO日期格式)字符串DateTime在使用它们的后来存储smalldatetime在sql.
当字符串转换为时datetimes,hour会神秘地添加到结果中.据我所知,在英国,我们需要夏令时(目前有效),但datetime.convert方法肯定能理解这一点吗?转换回字符串时,结果符合预期.
我写了一个小程序来说明问题(也包括我的理智的非ISO日期):
class Program
{
static void Main(string[] args)
{
//BB();
//Dist();
DateTime d1 = new DateTime();
DateTime d2 = new DateTime();
string d1s = "2010-09-13T09:30:01Z";
string d2s = "2010-09-13 09:30:01";
d1 = Convert.ToDateTime(d1s);
d2 = Convert.ToDateTime(d2s);
Console.WriteLine("d1s:{0} d1:{1} ", d1s, d1);
Console.WriteLine("d2s:{0} d2:{1} ", d2s, d2);
d1s = d1.ToString("u"); d2s = d2.ToString("u");
Console.WriteLine("\nd1: {0}", d1s);
Console.WriteLine("d2: {0}", d2s); …Run Code Online (Sandbox Code Playgroud) 我想向用户发送如下电子邮件:
这是验证码
用户名:xyz
代码:xyz
这是关于电子邮件的所有代码:
StringBuilder emailMessage = new StringBuilder();
emailMessage.Append("Here is the Verification Code.");
emailMessage.Append(Environment.NewLine);
emailMessage.Append("UserName: " + UsernameTextBox.Text).AppendLine();
emailMessage.AppendLine();
emailMessage.Append("Code: " + newCode);
MailMessage email = new MailMessage();
email.To.Add(new MailAddress(emailAddress));
email.Subject = "Subject";
email.Body = emailMessage.ToString();
email.IsBodyHtml = true;
//Send Email;
SmtpClient client = new SmtpClient();
client.Send(email);
Run Code Online (Sandbox Code Playgroud)
此代码使用单行发送邮件,即以下是验证码.用户名:xyz代码:xyx
我试过用过emailMessage.Append(Environment.NewLine);我也试过"\n",\r\n但没什么用.它有什么问题或者我错过了什么?