即使AllowMultiRowSelection 设置为 false,Telerik RadGrid 也会选择多行

发布于 2024-08-20 14:09:17 字数 6105 浏览 4 评论 0 原文

我有一个 RadGrid,它以编程方式创建行和列,并且有一个 RadAjaxManager 设置为更新 SelectedIndexChange 上的另一个面板。 RadGrid 还启用了滚动并禁用了多行选择。 RadGrid 按预期运行,但一旦您滚动,它就会开始收集选定的项目。我设置了断点并通过观察验证 SelectedItems.Count 是否大于 1。这也可以防止在滚动后选择先前选定的行。我曾尝试清除页面卸载事件中的选定项目,但当它呈现时,有时会显示多个选定的项目。我说有时是因为它与这个问题不一致。我注意到的唯一模式是滚动引发了问题。

第二个问题是,每次页面回发时,列标题都会消失。这让我很困惑,不知道是什么原因造成的。

我将不胜感激任何对此的建议。我也会包含我的代码。谢谢,我对糟糕的格式表示歉意。我还在想办法。

PS 我所包含的代码用于为列和行创建文本,因此不需要实际数据。您可以轻松地复制并粘贴相同的代码来查看我所看到的内容。
















<滚动AllowScroll="true" ScrollHeight="350" UseStaticHeaders="true" SaveScrollPosition="true" />
<选择AllowRowSelect="true"/>
<调整大小AllowColumnResize="true" />




未找到任何项目


< br> <选项卡>


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)  
{  

}  
}    

I have a RadGrid that has it's rows and columns being created programatically, and there is a RadAjaxManager that is set to update another Panel on SelectedIndexChange. The RadGrid also has scrolling enabled and multirowselect disabled. The RadGrid operates as supposed to, but as soon as you scroll it starts collecting selected items. I have set break points and verified through watches that SelectedItems.Count grows greater that 1. This also prevents from selecting previous selected rows after you've scrolled. I have tried clearing the selected items in the page unload event, but when it renders it sometimes shows more than one item selected. I say sometimes because it is not consistent with this issue. Only pattern I have noticed is that scrolling starts the problem.

The second issue is that each time the page posts back the column headers disappear. This one totally baffles me, not sure what's the cause for it.

I would appreciate any advice on this. I'll include my code as well. Thanks, and I appologize for the poor formatting. I'm still trying to figure it out.

P.S. The code I've included is set up to create text for the columns and rows, so no actual data is needed. You can easily copy and paste the same code to see what I'm seeing.

<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)  
{  

}  
}    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空‖城人不在 2024-08-27 14:09:17

检查您的代码后,我注意到您在 init 时生成了网格列!Page.IsPostBack。我从之前与 Telerik 的支持沟通中知道,当您在页面上静态地放置网格时,您应该在 PageLoad 上构建列!Page.IsPostBack-他们指示我帮助主题,在在线帮助中搜索它。

另外,如果我没记错的话,我在发行说明中读到,虚拟滚动和选定的项目存在一些问题。它应该在最新的 Q3 2009 SP2 版本中修复。

迪克

After inspecting your code I noticed that you generate the grid column on init when !Page.IsPostBack. I know from previous support communication with Telerik that when you have the grid statically on the page, you should build the columns on PageLoad when !Page.IsPostBack- they directed me to help topic, search for it in the online help.

Also if I recall well I read in release notes that there was some issue with virtually scrolling and selected items. It should be fixed in the latest Q3 2009 SP2 release.

Dick

策马西风 2024-08-27 14:09:17

(抱歉,我帮不上忙,但是)你为什么不发帖到 telerik 论坛 或创建支持票?通常您会在 24 小时内得到答复。

(sorry I can't help, but) Why don't you post to the telerik forums or create a support ticket? Usually you'll get an answer within 24 hours.

捶死心动 2024-08-27 14:09:17

这是按钮代码
此代码可以帮助您删除在 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();
                }
            }

        }

this is a Button code
this code may help you to delete multiple record which checkbox you have selected in your 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();
                }
            }

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文