Below is the code i have created and wanted to group it based on "name" column. But i am not able to group it and normal values are being rendered in the grid...
| RadGrid radGrid1 = new RadGrid(); |
| radGrid1.ID = "radgrid1"; |
| radGrid1.DataSourceID = "SqlDataSource1"; |
| radGrid1.GridLines = GridLines.None; |
| GridTableView gridTableView = new GridTableView(radGrid1); |
| gridTableView.GroupsDefaultExpanded = true; |
| gridTableView.DataSourceID = "SqlDataSource1"; |
| GridGroupByExpression expression = new GridGroupByExpression(); |
| GridGroupByField gridGroupByField = new GridGroupByField(); |
| gridGroupByField = new GridGroupByField(); |
| gridGroupByField.FieldName = "name"; |
| gridGroupByField.HeaderText = "Name"; |
| expression.SelectFields.Add(gridGroupByField); |
| gridGroupByField = new GridGroupByField(); |
| gridGroupByField.FieldName = "name"; |
| gridGroupByField.HeaderText = "Name"; |
| expression.GroupByFields.Add(gridGroupByField); |
| gridTableView.GroupByExpressions.Add(expression); |
| this.Controls.Add(radGrid1); |
<telerik:GridTemplateColumn UniqueName="ContactName" InitializeTemplatesFirst="false" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<HeaderTemplate>
<table id="Contact" cellspacing="0" style="width: 100%;">
<colgroup>
<col />
<col />
</colgroup>
<tr>
<td colspan="2" align="center" style="width: 100%; text-align: center;">
<%= Header.Value%>...............Header is dynamic...in my case..it is from database..
</td>
</tr>
<tr>
<td style="width: 50%" align="center">
Contactname
</td>
<td style="width: 50%" align="center">
Contactaddress
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellspacing="0" style="width: 100%;" class="myTable">
<colgroup>
<col />
<col />
</colgroup>
<tr>
<td style="width: 50%" align="right">
<%# Eval("Contactname") %>
</td>
<td style="width: 50%" align="right">
<%# Eval("Contactaddress") %>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
I want to apply sorting for this ...column..How???
If i am using below code for sorting
<asp:LinkButton CssClass="Button" ID="btnContName" ToolTip="Sort by ContactName"
CommandName='Sort' CommandArgument='ContactName' runat="server" />
In My case.. button text should be dynamic............it will come from database.....
And Export to excel also i am using..When i am exporting to excel it is not displaying header text.....in excel sheet..
My questions are...
1)How to apply sorting in this column.....which has dynamic text.
2)how to export to excel...when we applied sorting??
3)..Header Text will be dynamic..in this columns?????????????????
Thanks in advance..
SANNIDHI
| <telerik:RadGrid ID="grdRepairs" runat="server" Skin="Simple" GridLines="None" OnItemCommand="grdRepairs_ItemCommand" | |
| OnSelectedIndexChanged="grdRepairs_SelectedIndexChanged" | |
| OnItemDataBound="RadGrid1_ItemDataBound" AllowSorting="True" AutoGenerateColumns="False" | |
| AllowPaging="True" AllowCustomPaging="true" VirtualItemCount="10000" onsortcommand="grdRepairs_SortCommand" PageSize="7" Height="250px"> | |
| <MasterTableView CellSpacing="-1" clientDataKeyNames="ORDERID, PROPREF"> | |
| <Columns> | |
| <telerik:GridBoundColumn DataField="ORDERID" DataType="System.Int32" HeaderText="ORDERID" ReadOnly="True" SortExpression="ORDERID" | |
| UniqueName="ORDERID"> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="PROPREF" HeaderText="PROPREF" SortExpression="PROPREF" UniqueName="PROPREF"> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="FAULTREPORTED" HeaderText="FAULTREPORTED" SortExpression="FAULTREPORTED" | |
| UniqueName="FAULTREPORTED" ItemStyle-Width="300px" HeaderStyle-Width="350px" ItemStyle-Wrap="false"> | |
| <HeaderStyle Width="350px" /> | |
| <ItemStyle Width="300px" Wrap="False" /> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="NEARCOMPLETEDATETIME" DataType="System.DateTime" HeaderText="NEARCOMPLETEDATETIME" | |
| SortExpression="NEARCOMPLETEDATETIME" UniqueName="NEARCOMPLETEDATETIME"> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="STATUS" HeaderText="STATUS" | |
| SortExpression="STATUS" UniqueName="STATUS"> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="CONTRACT" HeaderText="CONTRACT" SortExpression="CONTRACT" UniqueName="CONTRACT"> | |
| </telerik:GridBoundColumn> | |
| </Columns> | |
| </MasterTableView> | |
| <ClientSettings AllowRowsDragDrop="False" Resizing-AllowRowResize="false"> | |
| <DataBinding EnableCaching="True"> | |
| </DataBinding> | |
| <Selecting AllowRowSelect="True" /> | |
| <ClientEvents OnRowContextMenu="RowContextMenu" OnRowSelected="RowSelected" /> | |
| <Scrolling AllowScroll="True" UseStaticHeaders="True" /> | |
| </ClientSettings> | |
| </telerik:RadGrid> |
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) | |
| { | |
| if (e.Item is GridDataItem) | |
| { | |
| TimeSpan ts = new TimeSpan(1, 0, 0, 0); | |
| GridDataItem dataItem = (GridDataItem)e.Item; | |
| if (dataItem["NEARCOMPLETEDATETIME"].Text == string.Empty || dataItem["NEARCOMPLETEDATETIME"].Text == "" || dataItem["NEARCOMPLETEDATETIME"].Text == " ") | |
| { | |
| dataItem.BackColor = Color.White; | |
| } | |
| else | |
| { | |
| if (DateTime.Today > DateTime.Parse(dataItem["NEARCOMPLETEDATETIME"].Text)) | |
| { | |
| dataItem.BackColor = Color.Orange; | |
| } | |
| else if (DateTime.Today == DateTime.Parse(dataItem["NEARCOMPLETEDATETIME"].Text)) | |
| { | |
| dataItem.BackColor = Color.Red; | |
| } | |
| } | |
| } | |
| if (e.Item is GridPagerItem) | |
| { | |
| GridPagerItem pagerItem = (e.Item as GridPagerItem); | |
| pagerItem.PagerContentCell.Controls.Clear(); | |
| } | |
| } | |
| protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e) | |
| { | |
| txtTabName.Value = e.Tab.Text; | |
| var order = Pilot.Data.tbl_repair_order.LoadByStatus(Classes.Contexts.WEBSSCHEDULE_CONN(), RadComboBox1.SelectedValue, e.Tab.Text); | |
| grdRepairs.DataSource = order; | |
| grdRepairs.DataBind(); | |
| } | |
| } | |
| else | |
| { | |
| if (DateTime.Today > DateTime.Parse(dataItem["NEARCOMPLETEDATETIME"].Text)) | |
| { | |
| dataItem.BackColor = Color.Orange; | |
| } | |
| else if (DateTime.Today == DateTime.Parse(dataItem["NEARCOMPLETEDATETIME"].Text)) | |
| { | |
| dataItem.BackColor = Color.Red; | |
| } | |
| } | |
| } | |
| if (e.Item is GridPagerItem) | |
| { | |
| GridPagerItem pagerItem = (e.Item as GridPagerItem); | |
| pagerItem.PagerContentCell.Controls.Clear(); | |
| } | |
| } |
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Panel newPanel = new Panel();
dropdown =
new RadComboBox();
dropdown.ID =
Guid.NewGuid().ToString();
newPanel.Controls.Add(dropdown);
this.Controls.Add(newPanel);
}
EDIT: sorry, already fixed it. There were some other things going wrong in the user control which probably messed up the RadComboBox. This post may be deleted.