or
Protected Sub RadListView2_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles RadListView2.ItemDataBound If TypeOf e.Item Is RadListViewDataItem Then Dim signed As Label = DirectCast(e.Item.FindControl("Label6"), Label) Dim pnl1 As Panel = DirectCast(e.Item.FindControl("TopPanel"), Panel) Dim lbl4 As Label = DirectCast(e.Item.FindControl("Label4"), Label) Dim pnl2 As Panel = DirectCast(e.Item.FindControl("BottomPanel"), Panel) Dim btn1 As Button = DirectCast(e.Item.FindControl("Button1"), Button) Dim menu2 As RadMenu = DirectCast(sender.findcontrol("RadMenu2"), RadMenu) Dim img As RadBinaryImage = DirectCast(e.Item.FindControl("RadBinaryImage4"), RadBinaryImage) 'Dim fball As menu2. 'signed.Text = "True" 'Then 'DirectCast(e.Item.FindControl("Div1")) 'Div1.backgroundcolor = "00CC99" End If If Session("Signed") = 1 Then Dim menu2 As RadMenu = DirectCast(sender.findcontrol("RadMenu2"), RadMenu) Dim fball As RadMenuItem = DirectCast(menu2.FindItemByText("QuickFax (Signed)"), RadMenuItem) Dim fbsigned As RadMenuItem = DirectCast(menu2.FindItemByText("QuickFax (ALL)"), RadMenuItem) Dim img As RadBinaryImage = DirectCast(e.Item.FindControl("RadBinaryImage4"), RadBinaryImage) img.DataValue =<%# Bind("SignedImage") %> fball.Visible = True fbsigned.Visible = True End If<telerik:RadSplitBar id="RadSplitbar1" EnableResize="false" runat="server" CollapseMode="Forward"></telerik:RadSplitBar> <telerik:RadPane id="MiddlePane" runat="server"> <!-- Content --> <!--<td valign="Top">--> <table width="100%"> <tr> <td> <asp:updatepanel runat="server" ID="MasterUpdatePanel"><table><tr> <td width="100%" colspan="2"> <telerik:RadScheduler ID="SchedulerAttivita" runat="server" EnableCustomAttributeEditing="True" Width="100%" AllowDelete="False" AllowInsert="False" WeekView-HeaderDateFormat="dd/MM/yyyy" MonthView-UserSelectable="false" TimelineView-UserSelectable="false" DayView-UserSelectable="true" DayStartTime="<%# StartTime %>" DayEndTime="<%# EndTime %>" OverflowBehavior="Expand" WorkDayStartTime="<%# StartTime %>" WorkDayEndTime="<%# EndTime %>" ShowFooter="False" ShowAllDayRow="False" AppointmentStyleMode="Default" MinutesPerRow="<%# MinutesPerRow %>" FirstDayOfWeek="Monday" AdvancedForm-Enabled="false" LastDayOfWeek="Friday" DataKeyField="ID" DataStartField="DATA_INIZIO" DataEndField = "DATA_FINE" DataSubjectField="SUBJECT" SelectedView="WeekView" onappointmentclick="SchedulerAttivita_AppointmentClick" onformcreating="SchedulerAttivita_FormCreating" OnClientAppointmentMoving="OnClientAppointmentMoving" onnavigationcommand="SchedulerAttivita_NavigationCommand" Culture="it-IT" EnableAdvancedForm="False" HoursPanelTimeFormat="t"> <AdvancedForm Enabled="False" EnableCustomAttributeEditing="True"></AdvancedForm> <Localization HeaderDay="<%$ Resources:SchedulerHeaderDay %>" HeaderToday="<%$ Resources:HeaderToday %>" HeaderWeek="<%$ Resources:HeaderWeek %>" /> <TimelineView UserSelectable="False"></TimelineView> <WeekView HeaderDateFormat="dd/MM/yyyy"></WeekView> <MonthView UserSelectable="False"></MonthView> </telerik:RadScheduler> </td> </tr></table></asp:updatepanel> </td> </tr> </table></telerik:RadPane> </telerik:RadSplitter>
I am making a simple grid control using the radgrid which derives its structure(columns) from an xml and databind using client side web serivce. It works fine, render intially, paging/sorting work fine, I implement the client OnRowDataBound event and render hyperlinks also. When a postback happens from any other buttons on the page, the columns in the grid are duplicated.
Following is my simplified code:
aspx:
| <asp:Button ID="btnPostBack" runat="server" Text="PostBack" /> |
| <telerik:RadGrid ID="grid" runat="server" GridLines="None" AllowFilteringByColumn="false" |
| AllowSorting="true" AllowPaging="true" PageSize="10" AutoGenerateColumns="false"> |
| <ClientSettings> |
| <DataBinding SelectMethod="GetResults" /> |
| <ClientEvents /> |
| </ClientSettings> |
| <MasterTableView Width="100%" AutoGenerateColumns="false"> |
| </MasterTableView> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| </telerik:RadGrid> |
| protected override void OnInit(EventArgs e) |
| { |
| base.OnInit(e); |
| FillColumns(); |
| } |
| [Serializable] |
| public class Field |
| { |
| public String ColumnName { get; set; } |
| public String DisplayName { get; set; } |
| } |
| private void FillColumns() |
| { |
| List<Field> fields = new List<Field> |
| { |
| new Field { DisplayName = "ID", ColumnName = "ID" }, |
| new Field { DisplayName = "Name", ColumnName = "Name" }, |
| new Field { DisplayName = "Description", ColumnName = "Description" }, |
| new Field { DisplayName = "Location", ColumnName = "Location" } |
| }; |
| grid.MasterTableView.Columns.Clear(); |
| foreach (var field in fields) |
| { |
| GridBoundColumn col = new GridBoundColumn(); |
| grid.MasterTableView.Columns.Add(col); |
| col.DataField = field.ColumnName; |
| col.HeaderText = field.DisplayName; |
| if (field.ColumnName == "ID") |
| col.DataType = Type.GetType("System.Int32"); |
| } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| grid.ClientSettings.DataBinding.Location = ResolveUrl("~/SearchService.asmx"); |
| } |
| [WebService(Namespace = "http://tempuri.org/")] |
| [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
| [System.ComponentModel.ToolboxItem(false)] |
| // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. |
| [System.Web.Script.Services.ScriptService] |
| public class SearchService : System.Web.Services.WebService |
| { |
| [WebMethod(EnableSession = true)] |
| public Dictionary<String, Object> GetResults( |
| int startRowIndex, int maximumRows, |
| List<GridSortExpression> sortExpression, |
| List<GridFilterExpression> filterExpression) |
| { |
| DataTable dt = new DataTable(); |
| dt.Columns.Add("ID", Type.GetType("System.Int32")); |
| dt.Columns.Add("Name"); |
| dt.Columns.Add("Description"); |
| dt.Columns.Add("Location"); |
| for (int i = 0; i < 35; i++) |
| { |
| System.Data.DataRow dr = dt.NewRow(); |
| dr["ID"] = i; |
| dr["Name"] = "Name" + i; |
| dr["Description"] = "Description" + i; |
| dr["Location"] = "Location" + i; |
| dt.Rows.Add(dr); |
| } |
| return new Dictionary<String, Object> |
| { |
| { "Data", RowsToDictionary(dt, dt.Select(string.Format(" ID > {0} and ID < {1}", startRowIndex.ToString(), (startRowIndex + maximumRows).ToString()))) }, |
| { "Count", dt.Rows.Count } |
| }; |
| } |
| private static List<Dictionary<string, object>> RowsToDictionary(DataTable table, DataRow[] rows) |
| { |
| List<Dictionary<string, object>> objs = |
| new List<Dictionary<string, object>>(); |
| foreach (DataRow dr in rows) |
| { |
| Dictionary<string, object> drow = new Dictionary<string, object>(); |
| for (int i = 0; i < table.Columns.Count; i++) |
| { |
| drow.Add(table.Columns[i].ColumnName, dr[i]); |
| } |
| objs.Add(drow); |
| } |
| return objs; |
| } |