我有一个ASP.NET WebForms应用程序,并且遇到了我在ASP.NET中编写九个月的奇怪问题之一。
我添加了两个使用Telerik Radgrids的新页面。两个Radgrids是相同的,所以我将专注于其中一个,希望解决其中一个问题将解决另一个问题。
HTML
<telerik:RadGrid ID="_radgrid" runat="server" Width="100%" Visible="true"
AutoGenerateColumns="false" OnSortCommand="_btnSearch_Click" PagerStyle-AlwaysVisible="true"
Skin="Office2007" AllowFilteringByColumn="true" AllowSorting="true" AllowPaging="true"
PageSize="50" OnNeedDataSource="_radgrid_NeedDataSource" OnItemDataBound="_radgrid_OnItemDataBound"
AllowMultiRowSelection="true">
<MasterTableView AllowFilteringByColumn="true" CommandItemDisplay="TopAndBottom">
<CommandItemTemplate>
<asp:Button ID="_btnResolve" runat="server" Text="Resolve" OnClick="_btnResolve_Click"
Visible="False" ClientIDMode="Inherit" />
</CommandItemTemplate>
<NoRecordsTemplate>
No records to display.</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn DataField="Id" Visible="false" />
<telerik:GridBoundColumn DataField="Resolved" Visible="false" />
<telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" FooterText="CheckBoxSelect footer"
Visible="false" />
<telerik:GridHyperLinkColumn DataNavigateUrlFields="Id" AllowFiltering="false"
DataNavigateUrlFormatString="~/UpdatePage.aspx?Id={0}"
Text="Update" UniqueName="UpdateHyperLink" />
<telerik:GridBoundColumn DataField="TradingPartnerName" HeaderText="Trading Partner Name" />
<telerik:GridBoundColumn DataField="DocumentType" HeaderText="Transaction Set" />
<telerik:GridBoundColumn DataField="DocumentID" HeaderText="Document ID" />
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" />
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
</telerik:RadGrid>
代码背后
protected void _radgrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
Fill_radgrid();
}
private void Fill_radgrid(bool dataBind = false)
{
//Data Manager is a class that I built that makes all of the Database calls. It returns a DataSet
_grdNegativeAck.DataSource = DataManager.GetRecords(_txtBoxId.Text, txtBoxDocumentType.Text, _chkBoxIncludeResolved.Checked, int.Parse(_ddlTradingPartner.SelectedValue));
if (dataBind)
_grdNegativeAck.DataBind();
}
protected void _radgrid_OnItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridCommandItem)
{
//If the current user is authorized to resolve, show the Resolve button on the grid
if (currentUser.IsAuthorized))
{
GridCommandItem cmditem = (GridCommandItem)e.Item;
Button _btnResolve = (Button)cmditem.FindControl("_btnResolve");
_btnResolve.Visible = true;
_grdNegativeAck.MasterTableView.GetColumn("CheckboxSelectColumn").Visible = true;
}
}
else if (e.Item is GridDataItem)
{
//If the record is already resolved, do not show the checkbox on the side and color the record green
GridDataItem GDItem = e.Item as GridDataItem;
if (GDItem["Resolved"].Text.ToUpper() == "TRUE")
{
((e.Item as GridDataItem)["CheckboxSelectColumn"].Controls[0] as CheckBox).Visible = false;
(e.Item as GridDataItem).BackColor = System.Drawing.Color.Green;
}
}
}
这是事情变得有趣的地方。在我的localhost上,当使用相同的数据库时,我返回0条记录。我检查了我绑定的DataSet,实际上有0行。当我查询数据库时,我得到185条记录没问题。我仔细检查了传递给查询的参数,它们是相同的。当我在测试网站上放置相同的代码时,该页面将获得184条记录......当它应该完全匹配并获得185条记录时。
其他页面在我的本地主机或我的测试站点上没有任何记录。
我真的在这里结束了。有人遇到类似的情况或者有什么地方可以指出我吗?
答案 0 :(得分:0)
_grdNegativeAck.DataSource = DataManager.GetRecords(_txtBoxId.Text, txtBoxDocumentType.Text _chkBoxIncludeResolved.Checked, int.Parse(_ddlTradingPartner.SelectedValue));
在上面一行中,您在txtBoxDocumentType.Text之后缺少逗号(,)。
希望这能解决您的问题。