我已将gridview绑定到数据库,并在TICKER事件中加载。它运作良好,但问题是,当它重新绑定时,GIRDVIEW的布局和形状变得不正确和不安,有点混乱。
<asp:GridView ID="GridViewSmsComplaints" AllowPaging="True" PageSize="4" runat="server" AutoGenerateColumns="False" CssClass="mGrid" BorderColor="#333333" Width="550px" OnRowDataBound="GridViewSmsComplaints_RowDataBound" OnPageIndexChanging="GridViewSmsComplaints_PageIndexChanging" >
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" />
<asp:BoundField HeaderText="Recieving Date" DataField="RecievingDate" />
<%--<asp:BoundField HeaderText="ToMobileNo" DataField="ToMobileNo" /> --%>
<asp:BoundField HeaderText="FromMobileNo" DataField="FromMobileNo" />
<asp:BoundField HeaderText="Message" DataField="Message" >
<ItemStyle Wrap="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="IsComplaint">
<ItemTemplate>
<asp:CheckBox ID="ckboxIsComplaint" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Timer runat="server" Interval="20000" ID="RefreshSmsComplaints" OnTick="RefreshSmsComplaints_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
股票代码:
protected void RefreshSmsComplaints_Tick(object sender, EventArgs e)
{
// ReportViewer1.Visible = false;
foreach (GridViewRow row in GridViewSmsComplaints.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("ckboxIsComplaint");
if (checkbox.Checked == true)
{
CheckedRows.Add(row.RowIndex);
}
else
{
CheckedRows.Remove(row.RowIndex);
}
}
try
{
DateTime fromDate = DateTime.ParseExact(txtFromDate.Text, "dd/MMM/yyyy", null);
DateTime toDate = DateTime.ParseExact(txtToDate.Text, "dd/MMM/yyyy", null);
DataTable dt = ManageRecievedMessage.GetSmsComplaintsByDate(fromDate, toDate);
//GridViewSmsComplaints.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
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 for this date combination";
GridViewSmsComplaints.Visible = true;
//gridViewComplaintsBySubject.Visible = false;
}
}
catch
{
HiddenFieldSetMessage.Value = "SomethingWrong";
HiddenFieldShowMessage.Value = "True";
}
}