我从sql server store过程填充gridview。我的目的是在gridview中创建一个可编辑的复选框字段,我的意思是当gridview显示一个记录而不是Checkbox字段(IsComplaint)时,每行应该可以编辑,并且应该反映在数据库中。
protected void btnSearchByDate_Click(object sender, EventArgs e)
{
DateTime fromDate = DateTime.ParseExact(txtFromDate.Text, "dd/MMM/yyyy", null);
DateTime toDate = DateTime.ParseExact(txtToDate.Text, "dd/MMM/yyyy", null);
DataTable dt = ManageQueueBizz.GetSmsComplaintsByDate(fromDate, toDate);
if (dt.Rows.Count > 0)
{
GridViewSmsComplaints.DataSource = dt;
GridViewSmsComplaints.DataBind();
GridViewSmsComplaints.Visible = true;
//gridViewComplaintsBySubject.Visible = false;
}
else
{
dt.Rows.Add(dt.NewRow());
GridViewSmsComplaints.DataSource = dt;
GridViewSmsComplaints.DataBind();
int totalcolums = GridViewSmsComplaints.Rows[0].Cells.Count;
GridViewSmsComplaints.Rows[0].Cells.Clear();
GridViewSmsComplaints.Rows[0].Cells.Add(new TableCell());
GridViewSmsComplaints.Rows[0].Cells[0].ColumnSpan = totalcolums;
GridViewSmsComplaints.Rows[0].Cells[0].Text = "No Data Found";
GridViewSmsComplaints.Visible = true;
//gridViewComplaintsBySubject.Visible = false;
}
}
.aspx代码:
<asp:GridView ID="gridViewComplaintsByDate" AllowPaging="true" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" Width="408px" OnPageIndexChanging="gridViewComplaintsByDate_PageIndexChanging" OnSelectedIndexChanged="gridViewComplaintsByDate_SelectedIndexChanged">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" ForeColor="white" />
</asp:GridView>
<br />
</asp:Panel>
</div>