Dear All,
I am very new to RadGrid. So please let me know how I can get the following task done. I need to programmatically create an grid with multiple column types. A few columns need to have mulitple sub-columns inside. So as far as my understanding goes, I need to create template column to do this job. So I did the following code and it seems working. However, i do not know how to get the filtering and sorting working with these columns though. Your help will be highly appreciated!
Here is what I have done. The current problem is the the combombox that I added to the filter control does not keep its value after postback. Please let me know what is missing. Thanks.
| //the following is My template column which is extended |
| //from the GridTemplateColumn |
| public class ComparisonColumn : GridTemplateColumn |
| { |
| private string _VColName; |
| private string _TColName; |
| private string _DColName; |
| private string _HColName; |
| private string _FilterCol; |
| RadComboBox combo; |
| public ComparisonColumn(string HeaderColName) |
| : base() |
| { |
| _HColName = HeaderColName; |
| _VColName = HeaderColName; |
| _TColName = HeaderColName + "_T"; |
| _DColName = HeaderColName + "_D"; |
| DataField = _VColName; |
| } |
| //I added a combobox in the filter control cell. It has 3 items "C", "T" |
| //and "D". Each item represent a sub-column in this column. |
| //So user will select a sub-column to filter on by select a value in |
| // this dropdown list and then enter filter value into the filter textbox |
| //and do the filtering. |
| protected override void SetupFilterControls(TableCell cell) |
| { |
| base.SetupFilterControls(cell); |
| cell.VerticalAlign = VerticalAlign.Bottom; |
| combo = new RadComboBox(); |
| combo.ID = ("RadComboBox1" + this.UniqueName); |
| RadComboBoxItem c = new RadComboBoxItem("C"); |
| combo.Items.Add(c); |
| RadComboBoxItem t = new RadComboBoxItem("T"); |
| combo.Items.Add(t); |
| RadComboBoxItem d = new RadComboBoxItem("D"); |
| combo.Items.Add(d); |
| combo.Width = Unit.Percentage(20); |
| TextBox txBox = (TextBox)cell.Controls[0]; |
| txBox.TextChanged += this.textBox_TextValueChanged; |
| cell.Controls.AddAt(2, combo); |
| combo.SelectedIndexChanged += this.list_SelectedIndexChanged; |
| cell.Wrap = false; |
| } |
| private void list_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| RadComboBox o = (RadComboBox)sender; |
| _FilterCol = o.Text; |
| switch (_FilterCol) |
| { |
| case "C": DataField = _VColName; break; |
| case "T": DataField = _TColName; break; |
| case "D": DataField = _DColName; break; |
| default: |
| DataField = _VColName; |
| break; |
| } |
| } |
| private void textBox_TextValueChanged(object sender, EventArgs e) |
| { |
| GridFilteringItem filterItem = (GridFilteringItem)((TextBox)sender).NamingContainer; |
| _FilterCol = combo.Text; |
| if (_FilterCol == null || _FilterCol == "C" || _FilterCol == "") |
| { |
| DataField = _VColName; |
| } |
| else if (_FilterCol == "T") |
| { |
| DataField = _TColName; |
| } |
| else if (_FilterCol == "D") |
| { |
| DataField = _DColName; |
| } |
| } |
| //I was hopping to keep the selection in the combo box after postback |
| //(sorting). However, The following attempt does not work |
| protected override void SetCurrentFilterValueToControl(TableCell cell) |
| { |
| base.SetCurrentFilterValueToControl(cell); |
| RadComboBox combo = (RadComboBox)cell.Controls[2]; |
| if ((_FilterCol != string.Empty)) |
| { |
| combo.Text = _FilterCol; |
| } |
| } |
| } |
| //the header template |
| public class ComparisonHeaderTemplate : ITemplate |
| { |
| private string _headerTxt; |
| private string _VColName; |
| private string _TColName; |
| private string _DColName; |
| public ComparisonHeaderTemplate(string headerTxt, string dataFldText) |
| { |
| _headerTxt = headerTxt; |
| _VColName = dataFldText; |
| _TColName = dataFldText + "_T"; |
| _DColName = dataFldText + "_D"; |
| } |
| public void InstantiateIn(System.Web.UI.Control container) |
| { |
| Table table = new Table(); |
| TableRow row1 = new TableRow(); |
| TableRow row2 = new TableRow(); |
| TableCell cell11 = new TableCell(); |
| TableCell cell21 = new TableCell(); |
| TableCell cell22 = new TableCell(); |
| TableCell cell23 = new TableCell(); |
| table.Width = Unit.Percentage(100); |
| cell11.ColumnSpan = 3; |
| cell11.Width = Unit.Percentage(100); |
| cell21.Width = Unit.Percentage(33.3); |
| cell22.Width = Unit.Percentage(33.3); |
| cell23.Width = Unit.Percentage(33.4); |
| row1.Cells.Add(cell11); |
| row2.Cells.Add(cell21); |
| row2.Cells.Add(cell22); |
| row2.Cells.Add(cell23); |
| table.Rows.Add(row1); |
| table.Rows.Add(row2); |
| cell11.Text = _headerTxt; |
| cell21.Text = "Current"; |
| cell22.Text = "Threshold"; |
| cell23.Text = "Difference"; |
| table.HorizontalAlign = HorizontalAlign.Center; |
| table.GridLines = GridLines.None; |
| container.Controls.Add(table); |
| //container.Controls.Add(new LiteralControl("<br />")); |
| } |
| } |
| public class ComparisonItemTemplate : ITemplate |
| { |
| protected LiteralControl lControlV; |
| protected LiteralControl lControlT; |
| protected LiteralControl lControlD; |
| private string colnameV; |
| private string colnameT; |
| private string colnameD; |
| public ComparisonItemTemplate(string cName) |
| { |
| colnameV = cName; |
| colnameT = cName + "_T"; |
| colnameD = cName + "_D"; |
| } |
| public void InstantiateIn(System.Web.UI.Control container) |
| { |
| lControlV = new LiteralControl(); |
| lControlV.ID = colnameV; |
| lControlV.DataBinding += new EventHandler(lControl_DataBinding); |
| lControlT = new LiteralControl(); |
| lControlT.ID = colnameT; |
| lControlT.DataBinding += new EventHandler(lControl_DataBinding); |
| lControlD = new LiteralControl(); |
| lControlD.ID = colnameD; |
| lControlD.DataBinding += new EventHandler(lControl_DataBinding); |
| Table table = new Table(); |
| TableRow row1 = new TableRow(); |
| //TableRow row2 = new TableRow(); |
| TableCell cell11 = new TableCell(); |
| TableCell cell12 = new TableCell(); |
| TableCell cell13 = new TableCell(); |
| table.Width = Unit.Percentage(100); |
| table.CellSpacing = 1; |
| cell11.Width = Unit.Percentage(33.3); |
| cell12.Width = Unit.Percentage(33.3); |
| cell13.Width = Unit.Percentage(33.4); |
| //TableCell cell22 = new TableCell(); |
| cell11.BackColor = Color.BlanchedAlmond; |
| cell12.BackColor = Color.Wheat; |
| cell13.BackColor = Color.LightSalmon; |
| row1.Cells.Add(cell11); |
| row1.Cells.Add(cell12); |
| row1.Cells.Add(cell13); |
| //row2.Cells.Add(cell22); |
| table.Rows.Add(row1); |
| //table.Rows.Add(row2); |
| cell11.Controls.Add(lControlV); |
| cell12.Controls.Add(lControlT); |
| cell13.Controls.Add(lControlD); |
| container.Controls.Add(table); |
| } |
| public void lControl_DataBinding(object sender, EventArgs e) |
| { |
| LiteralControl l = (LiteralControl)sender; |
| GridDataItem container = (GridDataItem)l.NamingContainer; |
| String colName = l.ID; |
| l.Text = ((DataRowView)container.DataItem)[colName].ToString() + "<br />"; |
| } |
| } |
LinqToSql.TelerikSamplesDataContext ?

| <telerik:RadScheduler runat="server" ID="RadScheduler" Skin="Sunset" MinutesPerRow="60"> |
| <WebServiceSettings Path="SchedulerWebService.asmx" ResourcePopulationMode="ServerSide" /> |
| </telerik:RadScheduler> |
| public class SchedulerDbProvider : SchedulerProviderBase |
| { |
| public override IEnumerable<Appointment> GetAppointments(RadScheduler owner) |
| { |
| int mpr = owner.MinutesPerRow; /* MinutesPerRow always = 30 */ |
| /* ... */ |
| } |
| } |
I have a form with a RadNumeric Textbox on it and here are the following results…
34.5 = 35 (rounding away from zero)
34.6 = 35 (rounding away from zero)
**** -34.5 = -34 (rounding closer to zero) ****
-34.6 = -35 (rounding away from zero)
The question I have, is why does .5 round closer to zero when it is a negative number? Is there a way to achieve the expected results…
34.5 = 35 (rounding away from zero)
34.6 = 35 (rounding away from zero)
**** -34.5 = -35 (rounding away from zero) ****
-34.6 = -35 (rounding away from zero)
Thanks,
Steve

function
OnClientShow(sender, eventArgs) {
var wnd = $find("<%= rl.ClientID %>");
slider.repaint();}
Unfortunately it does not compile since the "rl" control is inside a ContentTemplate and I do not know how to access this element from javscript.
Any help?
| <telerik:RadGrid ID="RadGrid1 > |
| <Columns> |
| <telerik:GridDateTimeColumn DataField="CreationDate" DataType="System.DateTime " /> |
| <Columns> |
| </telerik:RadGrid> |
| //data is IEnumerable collection of data objects |
| // filter is a filter expression generated by grid , which is converted to string like this : |
| //string filter = string.format("{0}.{1}(\"{2}\")",item.FieldName, item.FilterFunction, item.FieldValue) |
| IQueryable query = data.AsQueryable(); |
| queryquery = query.Where(filter); |