Telerik Forums
UI for ASP.NET AJAX Forum
7 answers
439 views
Hi,

I have a scenario where I need to loop through the number of rows in the detail table for each row and read the columns in the detail table.

I am binding my grid to a datasource with the relation defined.
I am unable to read the child rows in my ItemDataBound event. I tried using dataItem.childItem but my child Item always comes null.

I am not sure my detail table is getting any data or not.
I don't want to show my detail table to the user just want to read the values in the detail table.

Below is how my detail table is defined:
<MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="true" CommandItemDisplay="Top"
                        EnableNoRecordsTemplate="true">                                             
                        <Columns>
                            ......
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView DataKeyNames="AccountID" Width="100%" DataMember="FundBalance" HierarchyLoadMode="ServerBind">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="AccountID" MasterKeyField="AccountID" />
                                </ParentTableRelation>
                                <Columns>
                                    <telerik:GridBoundColumn DataField="AccountID" UniqueName="AccountID">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="FundTypeID" UniqueName="FundTypeID">
                                    </telerik:GridBoundColumn>                                   
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginBalanceShares" DataField="BeginBalanceShares">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginPrice" DataField="BeginPrice" >
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginBalanceDollars" DataField="BeginBalanceDollars">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="EndBalanceShares" DataField="EndBalanceShares">
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                    </MasterTableView>
 
 
My datasource is defined as:
 
public static DataTable ListByPlanAndDateRange(int planID, DateTime beginDate, DateTime endDate)
        {
            DataSet ds = DBRoutines.wusp_PeriodSummaryByFund_ListByPlanAndDateRange(planID, beginDate, endDate);
            ds.Tables[0].TableName = "FundBalance";
            ds.Tables[1].TableName = "SourceContribution";
            ds.Relations.Add("BalanceRelation", ds.Tables[0].Columns[Fields.FundID], ds.Tables[1].Columns[Fields.FundID], false);
            return ds.Tables[0];
        }

Basically I have a asp.net gridview to migrate from and currently I am using this to access the child rows:
protected void balances_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                DataRow[] drSubBalance = drv.Row.GetChildRows("BalanceRelation");
            }
        }
I want to do something similar in radgrid.

I have spent 2 days trying to figure this out. Please provide some help!
MBEN
Top achievements
Rank 2
Veteran
 answered on 07 Dec 2011
6 answers
149 views
I'm following your demo called Grid Heirachy with Templates. It shows a list of sales people and if you click the left column down arrow, it displays 3 tabs (sales, contact info, chart), each tab is designed with a RadPageView. It does work. However, the problem I have is when you load the page it executes the all queries to the database for each tab for every visible employee in the grid, all on page load. So if I have 50 rows in the main grid and 3 tabs (with scrolling enalbed naturally), 150 queries get executed all at once. This can be very bad for performance especially if I increase the rows on the main grid to a much higher number (which is what I need to do). I plan to show about 100 rows of data, plus add a few more tabs totaling 5 tabs of information, so I'd have 500 queries execute all on page load! on every postback too!

Not only is this a performance issue, it's also a stale data issue. If it's a highly active database with lots of inserts/updates going on, a grid user might wait 20 minutes, click the down arrow and see the orders with out-of-date information since a person somewhere else in the company might have since edited many rows of that order data for that sales person. 

The solution is: Those 3 sub tabs should only execute their queries when the user clicks the down arrow to make them visible, per employee. How can that be accomplished?

Thank you.
David
Top achievements
Rank 1
 answered on 07 Dec 2011
7 answers
153 views
I created the menu programmatically.
and I've a problem with some witdh of group. I need change the width of somes groups.

Attach an image

How I can fix this?
I try with:
-  group.Style.add(.....Width, "100px") but does not work.
- by css .RadRibbonBar .rrbMenuGroupIn {
    padding: 1px 20px 1px 20px;
}but does not work.

I need a quickly solution for not change a all code,

regards
July
Top achievements
Rank 2
 answered on 07 Dec 2011
1 answer
68 views
Does the RadGrid webpart support creating a heirarchy when the child item resides in a folder and if so how does one turn that setting on? An initial out of the box example I have tried does not seem to allow for this, all items returns must be at the root of the Sharepoint list.

Jon
Tsvetoslav
Telerik team
 answered on 07 Dec 2011
1 answer
180 views

Dear all,

I have a user control with (RadAjaxProxyManager) and the (RadAjaxManager) on the ASP.NET page where the user control lives 

I need to put the below JS function isnide .JS file not on the page directly. I want to get rid of the RadCodeBlock tag as well I'm combining JS in files. I dont want to have inline JS functions on ASP.NET pages.

<rad:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
 function refreshAttachmentGrid(arg) {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RefreshAttachment");
}
</script>
</rad:RadCodeBlock>


The code works fine, all I need is to move it to JS file.

Thanks in advance.

Taiseer

Andrey
Telerik team
 answered on 07 Dec 2011
5 answers
156 views
Will there be any tutorials of how to integrate asp.net controls with kendoui

cheers

Jason
Sebastian
Telerik team
 answered on 07 Dec 2011
1 answer
124 views
IS IT POSSIBLE TO SHOW RELATED DATA OF EACH SLICE IN PIE CHART.LIKE CLICK EVENTS
Giuseppe
Telerik team
 answered on 07 Dec 2011
13 answers
199 views
Hello,

I am using RadDatePicker and having the width issue..no matter how much i fix it it always takes up the whole page space....http://www.telerik.com/community/forums/aspnet-ajax/input/raddatepicker-calendar-width.aspx..having a similar issue as is mentioned in this thread but in the end part someone said that it is solved in the next release I have the latest version of telerik

2011.2.712.35  but am still having this issue..It works fine in firefox,chrome but not in IE8...
Can someone please help me with this.

Thanks


Keith
Top achievements
Rank 1
 answered on 07 Dec 2011
4 answers
229 views

Hello everyone and special thanks to Princy!

I am using a Radgrid with a Radwindow on Editing , you can see all about it in “Demo/Asp.Net Ajax/Window/Edit Dialog For RadGrid”

I tried it to customize it  in my Project logic and every thing is fine when I use the same structure(DefaultCS.aspx, and code behind and EditForm and its codebehind).

But  I am using a UserControl instead of aspx file ,as follow :

Root

.

.

.

Folder :Usercontrols

                                                ChargePanel.ascx(Instead of DefaultCS.aspx)[Inherited from SiteMasterpage]

                                                EditForm.aspx  

SiteMasterPage.master

 

When I click On Edit Button everything is true still, and works fine ,and the Grid will be updated after closing windows with some Java Script Code,after do that if I tend to edit another row when I click the Edit button It will raise  an error!

                Microsoft JScript runtime error: 'null' is null or not an object

 

Here is my Code,I have  tried  to find a solution from Many posts but I didn’t find anything to help me…

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChargePanelCS.ascx.cs"
    Inherits="UserControls_ChargePanel" %>
<telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
    <style type="text/css">
        .orderText
        {
            font: normal 12px Arial,Verdana;
            margin-top: 6px;
        }
        .expandImage
        {
            display: inline-block;
            background-image: url('<%= Page.ResolveUrl("~/Common/styles09/sprite09.gif")%>');
            background-position: -596px -1191px;
            background-repeat: no-repeat;
            width: 15px;
            height: 15px;
        }
        * html .expandImage
        {
            background-position: -596px -1194px;
        }
        * + html .expandImage
        {
            background-position: -596px -1194px;
        }
    </style>
</telerik:RadCodeBlock>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function ShowEditForm(id, rowIndex) {
            var grid = $find("<%= RadGrid1.ClientID %>");
 
            var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
            grid.get_masterTableView().selectItem(rowControl, true);
 
            window.radopen("../UserControls/EditFormCS.aspx?PanelId=" + id, "UserListDialog");
            return false;
        }
        function ShowInsertForm() {
            window.radopen("../UserControls/EditFormCS.aspx", "UserListDialog");
            return false;
        }
        function refreshGrid(arg) {
            if (!arg) {
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
            }
            else {
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
            }
        }
        function RowDblClick(sender, eventArgs) {
            window.radopen("../UserControls/EditFormCS.aspx?PanelId=" + eventArgs.getDataKeyValue("PanelId"), "UserListDialog");
        }
    </script>
</telerik:RadCodeBlock>
   <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" CssClass="myRadGrid" AllowPaging="true"
            AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" PageSize="10"
            Font-Names="Tahoma" dir="rtl" AllowFilteringByColumn="true" OnUpdateCommand="RadGrid1_UpdateCommand"
            OnItemCreated="RadGrid1_ItemCreated">
            <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
                <Pdf PageHeight="297mm" PageWidth="210mm" PageTitle="SushiBar menu" />
            </ExportSettings>
            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" TableLayout="Auto"
                Font-Names="Tahoma" DataKeyNames="PanelId" EditMode="PopUp">
                <%--<EditFormSettings InsertCaption="ركورد جديد" CaptionFormatString="ويرايش" CaptionDataField="PanelId"
            PopUpSettings-Modal="true" FormCaptionStyle-Font-Names="Tahoma" EditColumn-HeaderStyle-Font-Names="Tahoma" />--%>
                <CommandItemTemplate>
                    <div style="padding: 5px 5px;" dir="rtl">
                        <asp:LinkButton ID="LinkButton4" runat="server" Font-Names="Tahoma" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Icons/Refresh.gif" />به روزآوري اطلاعات</asp:LinkButton>
                    </div>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        <ItemStyle CssClass="MyImageButton" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="PanelName" HeaderText="نام پنل"
                        SortExpression="PanelName" UniqueName="PanelName" ColumnEditorID="GridTextBoxColumn">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="رده بندي ارسال">
                        <ItemTemplate>
                            <telerik:RadRating dir="rtl" ID="RadRating1" runat="server" AutoPostBack="true" Value='<%# Convert.ToDouble(Eval("Used_Charges_Send"))/100000 %>'
                                OnRate="RadRating1_Rate" ReadOnly="true" Precision="Item" ItemCount="10" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="N_Charges_Send" HeaderText="شارژ ارسال"
                        SortExpression="N_Charges_Send" UniqueName="N_Charges_Send" ItemStyle-CssClass="grid_txt_NO"
                        ColumnEditorID="GridTextBoxColumn">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="Fake_Charges_Send" HeaderText="شارژ اضطراري"
                        SortExpression="Fake_Charges_Send" UniqueName="Fake_Charges_Send" ItemStyle-CssClass="grid_txt_NO"
                        ColumnEditorID="GridTextBoxColumn">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                        <ItemTemplate>
                            <asp:HyperLink ID="EditLink" runat="server" ToolTip="افزايش شارژ" ImageUrl="../Images/Icons/Credit.png"
                                Text="Charge"></asp:HyperLink>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <PagerStyle Mode="NumericPages" />
                <EditFormSettings ColumnNumber="3" CaptionDataField="PanelId" CaptionFormatString="ويرايش اطلاعات"
                    InsertCaption="" FormCaptionStyle-Font-Names="Tahoma" FormStyle-Font-Names="Tahoma">
                    <FormTableItemStyle Wrap="True"></FormTableItemStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="5" BorderColor="Yellow" CellPadding="3"
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" Font-Names="Tahoma" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="ثبت " UpdateText="ويرايش" UniqueName="EditCommandColumn1"
                        CancelText="لغو ">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="true" />
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
        </telerik:RadGrid>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" OnClientClose="refreshGrid" >
            <Windows>
                <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="320px"
                    Width="310px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
                    Modal="true" />
            </Windows>
        </telerik:RadWindowManager>
        <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumn" runat="server" TextBoxStyle-CssClass="GridTextBoxColumnEditor" />
        <asp:Label ID="Label1" runat="server" Width="410px"></asp:Label>
    </div>
    <!-- content end -->
    </form>
</body>
</html>
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
     
       if (e.Item is GridDataItem)
       {
           HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
           editLink.Attributes["href"] = "#";
           editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PanelId"], e.Item.ItemIndex);
       }
   }
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
   {
       if (e.Argument == "Rebind")
       {
           RadGrid1.MasterTableView.SortExpressions.Clear();
           RadGrid1.MasterTableView.GroupByExpressions.Clear();
           RadGrid1.Rebind();
       }
       else if (e.Argument == "RebindAndNavigate")
       {
           RadGrid1.MasterTableView.SortExpressions.Clear();
           RadGrid1.MasterTableView.GroupByExpressions.Clear();
           RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1;
           RadGrid1.Rebind();
       }
   }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditFormCS.aspx.cs" Inherits="UserControls_EditFormCS" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title>Edit dialog</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script type="text/javascript">
            function CloseAndRebind(args) {
                GetRadWindow().BrowserWindow.refreshGrid(args);
                GetRadWindow().close();
            }
 
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
 
                return oWindow;
            }
 
            function CancelEdit() {
                GetRadWindow().close();
            }
            function onError(input, args) {
                var message = "Invalid character: ";
 
                message += "accepts only numberic values.";
                document.getElementById("numInput").innerHTML = args.get_inputText();
                document.getElementById("numErrorOut").innerHTML = message;
            }
            function onKeyPress(input, args) {
 
                document.getElementById("numInput").innerHTML = "";
                document.getElementById("numErrorOut").innerHTML = "";
 
            }
            function Close() {
                GetRadWindow().Close();
            }
        </script>
        <asp:ScriptManager ID="ScriptManager2" runat="server" />
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
        <br />
        <br />
        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Number" NumberFormat-DecimalDigits="0">
            <ClientEvents OnError="onError" OnKeyPress="onKeyPress"></ClientEvents>
        </telerik:RadNumericTextBox>
        <asp:Button runat="server" Text="Submit" ID="btnSubmit" OnClick="Unnamed1_Click" />
        <asp:Button runat="server" Text="Reset" ID="btnReset" OnClick="btnReset_Click" Visible="false" />
    </div>
    <asp:Label ID="Label1" runat="server" Width="410px"></asp:Label>
    <div class="module" style="width: 448px; clear: both;">
        <table cellpadding="4" cellspacing="0" width="100%">
            <tbody>
                <tr>
                    <td>
                        <span id="numInput"></span>
                    </td>
                    <td>
                        <span id="numErrorOut" style="color: Red"></span>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    </form>
</body>
</html>
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
 
       
        this.Page.Title = "Editing record";
    }
protected void btnSubmit_Click(object sender, EventArgs e)
    {
 
        //Some Code here
 
       Label1.Text = "<script type='text/javascript'>Close()</" + "script>";
        
        }
 
 
 
 
 
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
       /SomeCode here
    }

L D
Top achievements
Rank 1
 answered on 07 Dec 2011
7 answers
409 views
Hello,

We want to create a WebForm with a RadGrid that should be able to show different datasources.  I started out with http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html help page, that explains how to dynamically create a grid structure. To be more flexible I used the NeedDataSource event handling, and everything works reasonably well. For this I got some helpful info from the http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-dynamically-needs-different-datasources-needdatasource-can-t-do-this.aspx forum page.

However I have two issues I'm unable to solve. 

1) If the user changes a column width and then switch to a different datasource we get a 'Cannot find a column with UniqueName '...' error. This is because it still refers to the previous grid layout. What code changes should I make to fix this?

2) I want to save the width of columns and the sort columns. But as the RadGrid is created dynamically in the Page_Init I don't have a clue how and when I should save the grid layout.

I  added  a small sample, based on the Northwind database, to show my current solution. Can someone instruct me how to solve my problems?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm9.aspx.cs" Inherits="WebApplication3.WebForm9"  Trace="false" %>
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head id="Head1" runat="server">
    <title></title>
</head>
 
<body class="BODY">
    <form runat="server" id="mainForm" method="post">
 
        <telerik:RadScriptManager ID="RadScriptManager" runat="server"></telerik:RadScriptManager>
        <!-- content start -->
 
        <!-- Rad Ajax Manager -->       
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
 
 
        <div id="menu" style="height:30px; margin-top:10px;">
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>customers</asp:ListItem>
                <asp:ListItem>orders</asp:ListItem>
            </asp:DropDownList>
        </div>
        <br />
 
        <div id="DivGrid1" style="height:200px; margin-top:10px;" >
 
            <telerik:RadGrid ID="RadGrid1" runat="server" >
            </telerik:RadGrid>
 
        </div>
 
        <!-- content end -->
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Telerik.Web.UI;
 
namespace WebApplication3
{
 
   public partial class WebForm9 : System.Web.UI.Page
   {
 
      myListview pageGrid = new myListview();
      List<myListviewColumn> gridColumn = new List<myListviewColumn>();
 
      protected void Page_Init(object sender, System.EventArgs e)
      {
         Grid1_PageInit();
      }
 
      private void Grid1_PageInit()
      {
 
         RadGrid1.Skin = "Office2010Blue";
         this.RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(this.RadGrid1_NeedDataSource);
 
         RadGrid1.Width = Unit.Percentage(100);
         RadGrid1.AllowPaging = true;
         RadGrid1.GroupingEnabled = false;
         RadGrid1.ShowGroupPanel = false;
         RadGrid1.ShowStatusBar = true;
         RadGrid1.AllowMultiRowSelection = true;
 
         RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
         RadGrid1.PagerStyle.AlwaysVisible = true;
 
         RadGrid1.ClientSettings.AllowDragToGroup = true;
         RadGrid1.ClientSettings.Selecting.AllowRowSelect = true;
         RadGrid1.ClientSettings.AllowColumnsReorder = true;
         RadGrid1.ClientSettings.AllowKeyboardNavigation = true;
 
         RadGrid1.ClientSettings.Scrolling.AllowScroll = true;
         RadGrid1.ClientSettings.Scrolling.UseStaticHeaders = true;
         RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Percentage(100);
 
         RadGrid1.ClientSettings.Resizing.AllowColumnResize = true;
         RadGrid1.ClientSettings.Resizing.EnableRealTimeResize = true;
         RadGrid1.ClientSettings.Resizing.ResizeGridOnColumnResize = true;
         RadGrid1.ClientSettings.Resizing.AllowResizeToFit = true;
 
         // Add Master Table
         RadGrid1.MasterTableView.PageSize = 20;
         RadGrid1.MasterTableView.AllowSorting = true;
         RadGrid1.AutoGenerateColumns = false;
         RadGrid1.MasterTableView.EnableColumnsViewState = false;
 
         string ddlValue = Request.Form.Get("DropDownList1");
         switch (ddlValue)
         {
            case "customers":
               goto default;
            case "orders":
               pageGrid.gridDbConnection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
               pageGrid.gridQuery = "SELECT OrderID, OrderDate, ShipName, ShipAddress FROM Orders";
               gridColumn.Clear();
               gridColumn.Add(new myListviewColumn(0, "orderid", "Order", AttributeType.String, 100));
               gridColumn.Add(new myListviewColumn(1, "orderdate", "Orderdatum", AttributeType.String, 100));
               gridColumn.Add(new myListviewColumn(2, "shipname", "Bedrijf", AttributeType.String, 100));
               gridColumn.Add(new myListviewColumn(3, "shipaddress", "Adres", AttributeType.String, 100));
               break;
            default:
               pageGrid.gridDbConnection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
               pageGrid.gridQuery = "SELECT CompanyName, ContactName, Address, City FROM Customers";
               gridColumn.Clear();
               gridColumn.Add(new myListviewColumn(0, "companyname", "Bedrijf", AttributeType.String, 200));
               gridColumn.Add(new myListviewColumn(1, "contactname", "Contactpersoon", AttributeType.String, 200));
               gridColumn.Add(new myListviewColumn(2, "address", "Adres", AttributeType.String, 200));
               gridColumn.Add(new myListviewColumn(3, "city", "Plaats", AttributeType.String, 200));
               break;
         }
 
         CreateListlayout();
 
      }
 
      private void CreateListlayout()
      {
 
         GridClientSelectColumn selectColumn;
         selectColumn = new GridClientSelectColumn();
         selectColumn.UniqueName = "ClientSelectColumn";
         selectColumn.HeaderStyle.Width = Unit.Pixel(35);
         selectColumn.Resizable = false;
         RadGrid1.MasterTableView.Columns.Add(selectColumn);
 
         GridBoundColumn boundColumn;
         for (int i = 0; i < gridColumn.Count; i++)
         {
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = gridColumn[i].AttributeName;
            boundColumn.HeaderText = gridColumn[i].Name;
            boundColumn.ItemStyle.Wrap = false;
            if (i < gridColumn.Count - 1) { boundColumn.HeaderStyle.Width = Unit.Pixel(gridColumn[i].Width); }
            RadGrid1.MasterTableView.Columns.Add(boundColumn);
         }
 
      }
 
      protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
      {
         SqlDataReader dr;
         dr = SqlRetrieve(pageGrid.gridQuery, pageGrid.gridDbConnection);
         RadGrid1.DataSource = dr;
      }
 
      protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
         RadGrid1.CurrentPageIndex = 0;
         RadGrid1.MasterTableView.SortExpressions.Clear();
         RadGrid1.Rebind();
      }
 
 
      // Retrieve data using a SQL Query
      public static SqlDataReader SqlRetrieve(string sql, string connectionString)
      {
 
         // Create the database connection
         SqlConnection dbConnection = new SqlConnection(connectionString);
 
         // Prepare the SQL command execution
         SqlCommand cmd = new SqlCommand(sql, dbConnection);
         cmd.CommandType = CommandType.Text;
 
 
         // Retrieve data with sqlDataReader
         try
         {
            dbConnection.Open();
            // Make sure the database connection is closed when the datareader is closed.
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
         }
         catch (SqlException dbex)
         {
            return null;
         }
         catch (Exception ex)
         {
            return null;
         }
 
      }
 
      public class myListview
      {
         public string gridQuery { get; set; }
         public string gridDbConnection { get; set; }
      }
 
      public class myListviewColumn
      {
         public int Index { get; set; }
         public string Name { get; set; }
         public string AttributeName { get; set; }
         public int Type { get; set; }
         public int Width { get; set; }
 
         public myListviewColumn(int index, string attributename, string name, int type, int width)
         {
            Index = index;
            Name = name;
            Type = type;
            Width = width;
            AttributeName = attributename;
         }
 
      }
 
   }
}

Kind Regards, Remco
Remco
Top achievements
Rank 1
 answered on 07 Dec 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?