2012-03-29 92 views
0

我有一个带有事件名称和两个日历控件的文本框来获得日期和一个按钮来显示一个gridview。 我需要显示有类似事件名称开始日期,并从数据库结束日期的细节电网..Gridview从按钮点击弹出窗口里面

我的代码是.aspx.cs

protected void lnbtnSearch_OnClick(object sender, EventArgs e) 
{ 
     SqlConnection conn = new SqlConnection("Data Source=CTSINDLFVMOSS;Initial Catalog=DB_CGTPO_DEVE;Persist Security Info=True;User ID=*****;Password=*****"); 
     SqlDataAdapter adapter = new SqlDataAdapter("select EventId,EventName,StartDate,EndDate,Tactics,Perct_VolLift,Perct_ROI from TableNamewhere ((EventName='" + textfield3 + "') and (StartDate= StartDate) and (EndDate= EndDate))", conn); 
     DataSet ds = new DataSet(); 
     adapter.Fill(ds); 
     grdEventDetails.DataSource = ds; 
     grdEventDetails. 
} 
+3

您打开SQL注入,使用参数。 – 2012-03-29 09:54:31

回答

1

设置grdEventDetails.AutoGenerateColumns = true; 添加grdEventDetails.DataBind();

但如果你没有手动定义列,它会看起来很丑(尤其是日期字段)。