2010-02-05 158 views
1

我有一個RadGrid,它具有以編程方式創建的行和列,並且有一個RadAjaxManager用於更新SelectedIndexChange上的另一個面板。 RadGrid也啓用了滾動功能並禁用了多重選擇。 RadGrid按照設想運行,但只要您滾動它就開始收集選定的項目。我設置了斷點並通過手錶進行了驗證,SelectedItems.Count增長爲1.這也防止了在滾動後選擇先前選定的行。我嘗試清除頁面卸載事件中的選定項目,但是當它呈現時,它有時會顯示多個選定項目。我有時說是因爲它不符合這個問題。我注意到的唯一模式是滾動開始出現問題。即使將AllowMultiRowSelection設置爲false,Telerik RadGrid也會選擇多行

第二個問題是每次頁面回發列標題消失。這一個完全讓我感到困惑,不知道是什麼原因造成的。

我希望對此有任何建議。我也會包含我的代碼。謝謝,我爲可憐的格式化道歉。我仍然試圖弄清楚。

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

} 
}  

回答

2

在檢查你的代碼後,我注意到當你在!Page.IsPostBack時在init上生成網格列。我從以前的Telerik支持溝通中知道,當你在頁面上靜態地顯示網格時,你應該在PageLoad上建立列!Page.IsPostBack-他們指示我幫助主題,在聯機幫助中搜索它。

此外,如果我記得我在發佈說明中看到,幾乎滾動和選擇的項目有一些問題。它應該在最新的Q3 2009 SP2版本中修復。

迪克

+0

謝謝迪克的回覆。您在某些已知問題的事實上是正確的,Telerik已通知我最新版本應該解決這些問題。所以我有一個工作,直到我們得到新的版本。解決方法是在Page_PreRender中檢查SelectedItems.Count,如果大於1,則刪除SelectedItems [0]。似乎現在工作。再次感謝。 – jhorton 2010-02-16 14:51:21

0

(抱歉,我不能幫助,但)你爲什麼不張貼到telerik forums或創建support ticket?通常你會在24小時內得到答案。

+0

我在那裏有一個,但說實話,我從這裏得到的答案比那裏運氣更多。 – jhorton 2010-02-05 18:14:11

0

這是一個按鈕代碼 這個代碼可以幫助你刪除的複選框您在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(); 
       } 
      } 

     } 
相關問題