Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
213 views
Ok, so I'll start off with what I'm having issues with and then paste code below.

I have a RadGrid that allows for grouping and sorting.  I have the RadGrid tied to a DataSet that is stored in ViewState.

I need to manually add columns in the code behind so that I can allow some to be hidden and also becasue we allow the users to add extra columns from the database.

After a lot of playing I thought I had it working, but now my problem is that when sorting the column headers go away.

The issue is, and I have no idea why it's designed this way, but on every single post back, the Column collection in the RadGrid keeps the column count and the number of columns there, but it clears all the properties on that column so that there is no header text, there is no DatatField property, there is DataType.

I just need to know why this does this and how I can get around it, it's been like 2 full days of frustration and trying to get those columns to be persistant across post backs.

RadGrid in aspx:
                        <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Office2007" Width="100%" BorderWidth="0px" 
                            GridLines="None" ShowGroupPanel="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource" 
                            OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" 
                            AllowMultiRowSelection="true" AutoGenerateColumns="true">  
                            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">  
                                <Selecting AllowRowSelect="True" /> 
                            </ClientSettings> 
                        </telerik:RadGrid> 
 

A lot of different RadGrid code in the codebehind:
        private DataSet dataSource  
        {  
            get { return (DataSet)ViewState["dataSource"]; }  
            set { ViewState["dataSource"] = value; }  
        }  
        public void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            RadGrid1.DataSource = dataSource;  
        }  
        protected void AddColumnsToRadGrid(string columnName, string columnText, Type dataType, bool display)  
        {  
            int test = 0;  
 
            GridBoundColumn newnewBoundColumn = new GridBoundColumn();  
            newBoundColumn.DataType = dataType;  
            newBoundColumn.DataField = columnName;  
            newBoundColumn.HeaderText = columnText;  
            newBoundColumn.Display = display;  
 
            if (_RadGrid1Columns == null)  
            {  
                _RadGrid1Columns = RadGrid1.Columns;  
                test = 1;  
            }  
 
            _RadGrid1Columns.Add(newBoundColumn);  
 
            if (test != 1)  
            {  
                RadGrid1.Columns.Clear();  
 
                foreach (GridColumn gc in _RadGrid1Columns)  
                    RadGrid1.Columns.Add(gc);  
            }  
        }  
        protected void AddColumnsToDataTable(DataTable table, List<JobAttributeValue> _javc)  
        {  
            System.Text.StringBuilder sb = new System.Text.StringBuilder();  
            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");  
            sb.AppendLine("<ArrayOfJobTicket xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");  
 
            int jrn = 0;  
            bool parseSuccess = false;  
            List<JobAttributeValue> matches = null;  
 
            foreach (DataRow row in table.Rows)  
            {  
                sb.AppendLine("<JobTicket>");  
 
                foreach (DataColumn column in table.Columns)  
                {  
                    sb.AppendLine(string.Format("<{0}>{1}</{2}>", column.ColumnName, row[column.ColumnName].ToString(), column.ColumnName));  
                    if (column.ColumnName == "JobRecordNumber")  
                    {  
                        parseSuccess = int.TryParse(row[column.ColumnName].ToString(), out jrn);  
 
                    }  
                }  
                if (parseSuccess)  
                {  
                    matches = _javc.FindAll(delegate(JobAttributeValue jav) { return jav.JobRecordNumber == jrn; });  
                    if (matches != null)  
                    {  
                        if(matches.Count == 1)  
                        {  
                            foreach (JobAttributeValue Attribute in matches)  
                                sb.AppendLine(string.Format("<{0}>{1}</{2}>", Attribute.AttributeName, Attribute.AttributeValue,Attribute.AttributeName));  
                        }  
                        else  
                            if(matches.Count > 1)  
                            {  
                                matches.Sort(delegate(JobAttributeValue obj1, JobAttributeValue obj2) {return obj1.AttributeValue.CompareTo(obj2.AttributeValue);} );  
                                foreach (JobAttributeValue Attribute in matches)  
                                {  
                                    if (matches.IndexOf(Attribute) == 0)  
                                        sb.AppendLine(string.Format("<{0}>{1}, ", Attribute.AttributeName, Attribute.AttributeValue));  
                                    else  
                                        if (matches.IndexOf(Attribute) == matches.Count - 1)  
                                            sb.Append(string.Format("{0}</{1}>", Attribute.AttributeValue, Attribute.AttributeName));  
                                        else  
                                            sb.Append(string.Format("{0}, ", Attribute.AttributeValue));  
                                }  
                            }  
                    }  
                }  
                else  
                {  
                    sb.AppendLine(string.Format("<{0}></{1}>", _javc[1].AttributeName, _javc[1].AttributeName));  
                }  
 
                sb.AppendLine("</JobTicket>");  
 
            }  
            sb.AppendLine("</ArrayOfJobTicket>");  
            //System.IO.File.WriteAllText("C:\\datasetoutfromSB.xml", sb.ToString());  
              
            TextReader tr = new StringReader(sb.ToString());  
            dataSource.Tables.Clear();  
            dataSource.ReadXml(tr, XmlReadMode.Auto);  
 
            AddColumnsToRadGrid(_javc[0].AttributeName, _javc[0].AttributeName, _javc[0].AttributeValue.GetType(), true);  
        }  
        protected void treeFolders_NodeClick1(object sender, RadTreeNodeEventArgs e)  
        {  
            //folderName = e.Node.Text;  
 
            //RadGrid1.CurrentPageIndex = 0;  
            //RadGrid1.Rebind();  
 
            //labelFrom.Text = String.Empty;  
            //labelDate.Text = String.Empty;  
            //labelSubject.Text = String.Empty;  
            //labelMessage.Text = String.Empty;  
 
            _currentSelectedNode = e.Node;  
 
            if (e.Node.Value != "")  
            {  
                string xmlValue = string.Empty;  
                if (e.Node != null)  
                    xmlValue = e.Node.Value.ToString();  
 
                if (xmlValue.Length > 0)  
                {  
                    JobTicketCollection JobTicketCollection = new JobTicketCollection();  
                    JobTicketCollection = JobTicketService.getJobsByFilter(xmlValue);  
                    if (JobTicketCollection != null)  
                    {  
                        if (JobTicketCollection.Count > 0)  
                        {  
                            Stream _stream = SerializationServices<JobTicketCollection>.SerializeToStream(JobTicketCollection);  
 
                            DataSet _dataSet = new DataSet();  
                            _dataSet.ReadXml(_stream, XmlReadMode.Auto);  
 
                            dataSource = _dataSet;  
 
                            // Add default columns to RadGrid  
                            AddColumnsToRadGrid("JobRecordNumber", "Job Record Number", typeof(Int32), true);  
                        }  
                    }  
                }  
                else  
                {  
                    DataSet _dataSet = new DataSet();  
                    dataSource = _dataSet;  
                }  
 
                RadGrid1.Rebind();  
            }  
        }  
        protected void btnStock_Click(object sender, EventArgs e)  
        {  
            List<int> jobRecNums = new List<int>();  
            foreach (DataRow dataRow in dataSource.Tables[0].Rows)  
                jobRecNums.Add(Convert.ToInt32(dataRow["JobRecordNumber"]));  
 
            List<JobAttributeValue> jobAttributeValueCollection = new List<JobAttributeValue>();  
            jobAttributeValueCollection = JobTicketService.getNewAttribute(jobRecNums, "ImprintLine_color");  
 
            AddColumnsToDataTable(dataSource.Tables[0], jobAttributeValueCollection);  
 
            RadGrid1.Rebind();  
        }  
 


Ok, so in explaination of what's going on in the code behind.
1. The dataSource DataSet is filled when you click on a treeNode.
2. The "JobRecordNumber" is added to the RadGrid Columns
3. When a user clicks the btnStock it goes out and adds a new column to dataSource and fills it with the different stocks.
4. Then it adds that column to the RadGrid.

This is my code, I'm just really wondering where I'm going wrong to make the columns in the RadGrid clear their properties on post back and also, if that's just how it is, how can I fix my code to work for me.

Thanks
Davey
David
Top achievements
Rank 1
 answered on 03 Mar 2008
2 answers
182 views
I am using the following RadAjaxManager code to control a RadDatePicker and a RadGrid.  I want the grid to update when either of those controls fires.  Changing the date in the date picker will load a new set of data in the grid.

It technically works, I guess, but not as well as I would expect when changing the date on the calendar.  When events fire on the grid, I can see the LoadingPanel during the duration of the update until the changes are processed.

When changing the date on the date picker, the loading panel only flashes on the grid and immediately disappears.  The update still takes another moment to occur.  (On the same note, the status bar of the grid also returns to "Ready" immediately even though the update is not complete.)

Is there something I have wrong in this declaration to cause this to happen?
Thanks,
Joel

<TELERIK:RadAjaxManager ID="AjaxManager" runat="server">
<AjaxSettings>
    <TELERIK:AjaxSetting AjaxControlID="rdtWorkDate">
        <UpdatedControls>
            <TELERIK:AjaxUpdatedControl ControlID="rgSchedule" LoadingPanelID="LoadingPanel" />
        </UpdatedControls>
    </TELERIK:AjaxSetting>
    <TELERIK:AjaxSetting AjaxControlID="rgSchedule">
        <UpdatedControls>
            <TELERIK:AjaxUpdatedControl ControlID="rgSchedule" LoadingPanelID="LoadingPanel" />
        </UpdatedControls>
    </TELERIK:AjaxSetting>
</AjaxSettings>
</TELERIK:RadAjaxManager>
<TELERIK:RadAjaxLoadingPanel runat="server" ID="LoadingPanel" Transparency="30" BackColor="#E0E0E0">
<img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0" />
</TELERIK:RadAjaxLoadingPanel>
Joel Kraft
Top achievements
Rank 2
 answered on 03 Mar 2008
3 answers
186 views
I am getting the above when trying to cast a datarow returned in a nodedatabound events' radtreenodeeventargs to a strongly typed datarow derived from the strongly typed datatable that the treeview was originally bound to.

To reproduce, just create a strongly typed dataset with one table, add a prometheus treeview to a page with an object datasource bound to the control that derives from the table you added to the dataset, then hook up the nodedatabound event for the control.

If you then create a datarow and try to cast it back to your strongly typed object it fails.

eg

protected
void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
{
DataRow datarow = ((DataRowView)e.Node.DataItem).Row;
MyDataset.MyDataRow myrow = (MyDataset.MyDataRow)datarow; 

Can someone please help me with this.

Darren
Atanas Korchev
Telerik team
 answered on 03 Mar 2008
4 answers
156 views
I have some pages with a masterpage and 1-3 radGrids and all is ajaxified. I want to be able to navigate from and to these pages with the grid information intact.
Has anyone implemented this functionality successfully in asp .net 2.0-3.0? And if so, how?

Regards, Magnus
mgns
Top achievements
Rank 1
 answered on 03 Mar 2008
1 answer
125 views
hi
in privuse version of radsplitter I set pane content url but that code dosn't work in new version. my code is like this:
1-    var splitter = <%= radsplitter1.ClientID%>;
2-    var pane = splitter.GetPaneById(<%= pane1.ClientID%>);
3-    if (pane == null)
4-        return
5-    pane.SetContentUrl('www.test.com');

when I run this javascript code it alert that object dosn't this property
error is in line 5
is there any one familier with this?
George
Telerik team
 answered on 03 Mar 2008
4 answers
167 views
I have some preliminary questions for using Scheduler.

1. I do not want to keep the ViewState for the Scheduler. So, in Page_PreRender I bind the Scheduler with appointments ( a custom class object list) everytime. I only set the RadScheduler1.DataSource and then call RadScheduler1.Rebind(). -- is this okay?

2. When the page loads first time it displays the results correctly (calls AppointmentCreated event too). But then when I change the date, it again fetches appointment for next date - there are appts for that date too - but then AppointmentCreated does not get called and the Scheduler is displayed empty. How can I make sure that Scheduler gets refreshed on every Page_PreRender or any other event like that.

3. The other thing is - I use RadTooltip in Scheduler. When OnAjax_Update() gets called, the .net calls PreRender again and it again binds the RadScheduler. I understand that I can't avoid it - so other approach would be to update RadScheduler in different events but not in PagePreRender. If I do that, then since I am not using ViewState, and call is made for Tooltip - will there be any problem? Or do you suggest any alternative for Tooltip - like calling PageMethods through Ajax to get the content to display in tooltip control and not go through whole page event cycle.

-Piyush



Dimitar Milushev
Telerik team
 answered on 03 Mar 2008
1 answer
240 views
I there is a double click client event and I am using it but I was wondering if there is anyway to have the event postback to a server side event also.  Essentially creating a double-click server-side event?
Atanas Korchev
Telerik team
 answered on 03 Mar 2008
2 answers
144 views

I need to implement a Scheduler which only the administrator users can insert, update and delete the event of the RadScheduler. Please tell me how to disable the delete event. Thank you very much.

Vinix
Top achievements
Rank 1
 answered on 03 Mar 2008
2 answers
92 views
I am having a little trouble with this one. I have a fields in our radgrid that is an id (int) which needs to be looked up for the text description.  I thought I could add a gridDrowndown control and bind it to display the text part in the grid row (dont need it for editing).  But it appears if i am correct that the gridDropDowncolumn is for when the grid is in edit mode only?

So how do i do lookup values for the grid display?
kyle
Top achievements
Rank 1
 answered on 03 Mar 2008
1 answer
87 views

OK, heres the deal... We are using SharePoint as a Web Content Management System.... So we have 1 master page with a few different Page Layouts created... We are using the Telerik Lite Editor... I have dissalowed the use of different font colors, font sizes, etc for our main system...

Now we have a request to have a different design (different master page), and in this I would like to give the users a little more flexibility... I dont mind if they use different fonts, colors, etc...

Both sites will be under the same domain... different subsites...

So basically my question is... Can I have the Telerik Lite Editor installed to handle one subsite to not allow the user to choose fonts, etc... and then in a different subsite allow the user to control fonts??

Let me know if this is not clear and you need more clarification...

Rumen
Telerik team
 answered on 02 Mar 2008
Narrow your results
Selected tags
Tags
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?