我有一个RadGrid,它的行和列是以编程方式创建的,并且有一个RadAjaxManager设置为更新SelectedIndexChange上的另一个Panel。 RadGrid还启用了滚动功能并禁用了multirowselect。 RadGrid按预期运行,但是一旦滚动它就会开始收集所选项目。我已设置断点并通过监视验证SelectedItems.Count增长大于1.这也阻止在滚动后选择先前选定的行。我已经尝试清除页面卸载事件中的所选项目,但是当它呈现时,它有时会显示多个项目被选中。我有时说,因为它与这个问题不一致。只有我注意到的模式是滚动才会启动问题。
第二个问题是,每次页面回发列标题时都会消失。这个让我很困惑,不知道是什么原因造成的。
我很感激有关这方面的任何建议。我也会包含我的代码。谢谢,我为糟糕的格式道歉。我还在努力解决这个问题。
P.S。我包含的代码设置为为列和行创建文本,因此不需要实际数据。您可以轻松复制并粘贴相同的代码,以查看我所看到的内容。
<rad:RadScriptManager ID="scm" runat="server"> </rad:RadScriptManager>
<rad:RadAjaxManager ID="AjaxManager" runat="server">
<AjaxSettings>
<rad:AjaxSetting AjaxControlID="grdCustomerAssignments">
<UpdatedControls>
<rad:AjaxUpdatedControl ControlID="grdCustomerAssignments" LoadingPanelID="pnlLoading1" />
</UpdatedControls>
</rad:AjaxSetting>
<rad:AjaxSetting AjaxControlID="grdCustomerAssignments">
<UpdatedControls>
<rad:AjaxUpdatedControl ControlID="pnlDetails" />
</UpdatedControls>
</rad:AjaxSetting>
</AjaxSettings>
</rad:RadAjaxManager>
<rad:RadGrid ID="grdCustomerAssignments" runat="server" Skin="WebBlue" AutoGenerateColumns="false" AllowMultiRowSelection="false" OnNeedDataSource="grdCustomerAssignments_NeedDataSource" OnSelectedIndexChanged="grdCustomerAssignments_SelectedIndexChanged" OnSortCommand="grdCustomerAssignments_SortCommand">
<ClientSettings EnablePostBackOnRowClick="true" >
<ClientEvents/>
<Scrolling AllowScroll="true" ScrollHeight="350" UseStaticHeaders="true" SaveScrollPosition="true" />
<Selecting AllowRowSelect="true" />
<Resizing AllowColumnResize="true" />
</ClientSettings>
<MasterTableView DataKeyNames="ID" >
<HeaderStyle Wrap="false" HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="true" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="false" />
<AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="false" />
<NoRecordsTemplate>
<div style="font-size:80%; color:Maroon;">No Items Were Found</div>
</NoRecordsTemplate>
</MasterTableView>
</rad:RadGrid>
<asp:Panel ID="pnlDetails" runat="server">
<rad:RadTabStrip ID="tabStrip" runat="server" Align="Justify" AppendDataBoundItems="false" SelectedIndex="0" MultiPageID="multiPage" Skin="WebBlue">
<Tabs></Tabs>
</rad:RadTabStrip>
<rad:RadMultiPage ID="multiPage" runat="server"></rad:RadMultiPage>
</asp:Panel>
protected DataTable Assignments { get; set; }
protected Dictionary<string, IList<int>> TabTitles { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
GetAssignments();
if (!IsPostBack)
AddColumnsToGrid();
}
protected void Page_Load(object sender, EventArgs e)
{
tabStrip.Tabs.Clear();
multiPage.Controls.Clear();
}
protected void Page_UnLoad(object sender, EventArgs e)
{
grdCustomerAssignments.MasterTableView.ClearSelectedItems();
}
protected void grdCustomerAssignments_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
grdCustomerAssignments.DataSource = Assignments;
}
protected void grdCustomerAssignments_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string id = ((RadGrid)sender).SelectedValue.ToString();
DataRow dataRow = null;
foreach (DataRow row in Assignments.Rows)
{
if (row["ID"].ToString() == id)
dataRow = row;
}
PopulateAssignmentDetail(dataRow);
}
catch (Exception ex)
{
}
}
protected void PopulateAssignmentDetail(DataRow datarow)
{
// just some code to populate the tabs.
}
protected void AddColumnsToGrid()
{
grdCustomerAssignments.MasterTableView.Columns.Clear();
for (int i = 1; i < 7; i++)
{
DataColumn column = Assignments.Columns[i];
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.HeaderText = column.Caption;
boundColumn.DataField = column.ColumnName;
grdCustomerAssignments.MasterTableView.Columns.Add(boundColumn);
}
}
private void GetAssignments()
{
if (Assignments == null)
Assignments = new DataTable();
if (TabTitles == null)
TabTitles = new Dictionary<string, IList<int>>();
try
{
Assignments.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < 50; i++)
{
Assignments.Columns.Add(new DataColumn("Column" + i.ToString()));
}
int columnIndex = 0;
int tabIndex = 0;
foreach (DataColumn column in Assignments.Columns)
{
if (columnIndex > 5)
{
string fieldCategory = "tab" + tabIndex.ToString();
if (tabIndex == 4)
tabIndex = 0;
else
tabIndex++;
if (!TabTitles.ContainsKey(fieldCategory))
{
IList<int> tmp = new List<int>();
tmp.Add(columnIndex);
TabTitles.Add(fieldCategory, tmp);
}
else
TabTitles[fieldCategory].Add(columnIndex);
}
columnIndex++;
}
for (int j = 0; j < 50; j++)
{
DataRow row = Assignments.NewRow();
foreach (DataColumn column in Assignments.Columns)
{
row[column.ColumnName] = column.ColumnName + "Row" + j.ToString();
}
Assignments.Rows.Add(row);
}
Assignments.AcceptChanges();
Session["Assignments"] = Assignments;
}
catch (Exception ex)
{
}
}
答案 0 :(得分:2)
检查完代码后,我注意到你在init.IsPostBack时生成了网格列。我从以前的支持与Telerik的沟通中知道,当你在网页上静态使用网格时,你应该在PageLoPostBack上构建列的页面!Page.IsPostBack-他们指导我帮助主题,在在线帮助中搜索它。
另外,如果我记得很清楚,我在发行说明中读到虚拟滚动和选定项目存在一些问题。它应该在最新的Q3 2009 SP2版本中修复。
迪克
答案 1 :(得分:0)
(抱歉,我无法帮助,但是)为什么不发布到telerik forums或创建support ticket?通常你会在24小时内得到答案。
答案 2 :(得分:0)
这是一个Button代码 此代码可以帮助您删除多个记录,您在RadGrid中选择了哪个复选框。
protected void Button3_Click(object sender, EventArgs e)
{
Area_Master Area;
int i;
foreach (GridDataItem item in Grd_Area.Items)//loops through each grid row
{
CheckBox chkBx = (CheckBox)item.FindControl("chkArea");
if (chkBx.Checked)
{
i = Convert.ToInt32(item.Cells[3].Text); //accessing cell using its ColumnUniqueName
var query = from obj in cnx.Area_Master where obj.PKAreaID == i select obj;
Area = query.FirstOrDefault();
cnx.DeleteObject(Area);
cnx.SaveChanges();
}
}
}