Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
257 views
hi anyone have idea about how to read the values of a hidden column in radgrid using updatecommand event? i have some hidden columns and need to retrieve those values when i click update link. (update cancel)

any help would be greatly appreciated.

Arun.K.S
Shinu
Top achievements
Rank 2
 answered on 20 May 2008
1 answer
307 views
Hello All

i am using the radgrid to display the data from the database and i receive the following error message

  

Server Error in '/' Application.

The control with ID 'rgAutoshipLeft' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The control with ID 'rgAutoshipLeft' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The control with ID 'rgAutoshipLeft' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.]
   Telerik.Web.UI.ScriptRegistrar.GetScriptManager(Control control) +175
   Telerik.Web.UI.RadCompositeDataBoundControl.get_ScriptManager() +34
   Telerik.Web.UI.RadCompositeDataBoundControl.RegisterScriptControl() +25
   Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e) +40
   Telerik.Web.UI.RadGrid.OnPreRender(EventArgs e) +41
   System.Web.UI.Control.PreRenderRecursiveInternal() +148
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Control.PreRenderRecursiveInternal() +233
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4421


Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

Shinu
Top achievements
Rank 2
 answered on 20 May 2008
1 answer
122 views
Hi all,

I am trying to bind the grid in the code behind and also the Hierarchy table with the code behind, I searched in the documentation but couldn't really get to a solution. If you could please direct me to the right spot in the documentation or video or let me know what I am doing wrong, I would really appreciate your help.

Here is my HTML
<radg:radgrid id="dgDep" runat="server" allowsorting="True" 
        autogeneratecolumns="False" gridlines="None" Width="689px" Skin="WebBlue">  
<MasterTableView DataKeyNames="ContactID,ContactIndic" HierarchyLoadMode="Client">  
 
    <Columns> 
      <radG:GridBoundColumn DataField="ContactID" Display="False" HeaderText="UniqueNumber" 
            ReadOnly="True" UniqueName="UniqueNumber, ContactIndic">  
      </radG:GridBoundColumn> 
      <radG:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn1">  
      </radG:GridEditCommandColumn> 
      <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" ReadOnly="True" 
            UniqueName="Contact">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Ext" HeaderText="Extension" ReadOnly="True" 
            UniqueName="Ext">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Fax" HeaderText="Fax" UniqueName="Fax">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP">  
      </radG:GridBoundColumn> 
      <radG:GridTemplateColumn DataField="ContactIndic" HeaderText="Live" UniqueName="ContactIndic">  
        <ItemTemplate> 
            <asp:CheckBox ID="cbIndic" runat="server" Enabled="false" /> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:CheckBox ID="EditLive" runat="server" Checked='<%# Bind("ContactIndic")%>' /> 
        </EditItemTemplate> 
      </radG:GridTemplateColumn> 
 
    </Columns> 
      
    <RowIndicatorColumn Visible="False">  
        <HeaderStyle Width="20px" /> 
    </RowIndicatorColumn> 
    <ExpandCollapseColumn> 
        <HeaderStyle Width="19px" /> 
    </ExpandCollapseColumn> 
    <DetailTables> 
        <radG:GridTableView runat="server" HierarchyLoadMode="ServerBind">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False">  
                <HeaderStyle Width="19px" /> 
            </ExpandCollapseColumn> 
            <Columns> 
                <radG:GridBoundColumn DataField="DepID" Display="False" HeaderText="UniqueNumber1" 
                    ReadOnly="True" UniqueName="DepID">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" UniqueName="Contact1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="EXT" HeaderText="Ext" UniqueName="Ext1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP1">  
                </radG:GridBoundColumn> 
            </Columns> 
            <ParentTableRelation> 
                <radG:GridRelationFields DetailKeyField="DepID" MasterKeyField="ContactID" /> 
            </ParentTableRelation> 
        </radG:GridTableView> 
    </DetailTables> 
</MasterTableView> 
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">  
        </ClientSettings> 
</radg:radgrid> 
And here is the vb code behind.
    Protected Sub dgDep_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles dgDep.ItemDataBound  
        'If TypeOf e.Item Is GridDataItem Then  
        If TypeOf e.Item Is GridDataItem AndAlso (e.Item.OwnerTableView Is dgDep.MasterTableView) Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim strChk As String = item.GetDataKeyValue("ContactIndic").ToString()  
            Dim chkbx As CheckBox = DirectCast(item("ContactIndic").FindControl("cbIndic"), CheckBox)  
            Dim DepID As String = item.GetDataKeyValue("ContactID").ToString()  
            If strChk = "1" Then 
                chkbx.Checked = True 
            Else 
                chkbx.Checked = False 
            End If 
 
            Dim getDS2 As New DataSet  
            getDS2 = dataConn.PhoneGetEachDep(DepID)  
            dgDep.MasterTableView.DetailTables.Item(0).DataSource = getDS2  
 
        End If 
    End Sub 
 
    Protected Sub dgDep_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles dgDep.NeedDataSource  
        Dim getDS As New DataSet  
        getDS = dataConn.AllDep()  
        dgDep.DataSource = getDS.Tables(0).DefaultView  
    End Sub 

Thank you very much,
Shehab
Princy
Top achievements
Rank 2
 answered on 20 May 2008
1 answer
95 views
Hi all,

I am trying to bind the grid in the code behind and also the Hierarchy table with the code behind, I searched in the documentation but couldn't really get to a solution. If you could please direct me to the right spot in the documentation or video or let me know what I am doing wrong, I would really appreciate your help.

Here is my HTML
<radg:radgrid id="dgDep" runat="server" allowsorting="True" 
        autogeneratecolumns="False" gridlines="None" Width="689px" Skin="WebBlue">  
<MasterTableView DataKeyNames="ContactID,ContactIndic" HierarchyLoadMode="Client">  
 
    <Columns> 
      <radG:GridBoundColumn DataField="ContactID" Display="False" HeaderText="UniqueNumber" 
            ReadOnly="True" UniqueName="UniqueNumber, ContactIndic">  
      </radG:GridBoundColumn> 
      <radG:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn1">  
      </radG:GridEditCommandColumn> 
      <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" ReadOnly="True" 
            UniqueName="Contact">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Ext" HeaderText="Extension" ReadOnly="True" 
            UniqueName="Ext">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Fax" HeaderText="Fax" UniqueName="Fax">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP">  
      </radG:GridBoundColumn> 
      <radG:GridTemplateColumn DataField="ContactIndic" HeaderText="Live" UniqueName="ContactIndic">  
        <ItemTemplate> 
            <asp:CheckBox ID="cbIndic" runat="server" Enabled="false" /> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:CheckBox ID="EditLive" runat="server" Checked='<%# Bind("ContactIndic")%>' /> 
        </EditItemTemplate> 
      </radG:GridTemplateColumn> 
 
    </Columns> 
      
    <RowIndicatorColumn Visible="False">  
        <HeaderStyle Width="20px" /> 
    </RowIndicatorColumn> 
    <ExpandCollapseColumn> 
        <HeaderStyle Width="19px" /> 
    </ExpandCollapseColumn> 
    <DetailTables> 
        <radG:GridTableView runat="server" HierarchyLoadMode="ServerBind">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False">  
                <HeaderStyle Width="19px" /> 
            </ExpandCollapseColumn> 
            <Columns> 
                <radG:GridBoundColumn DataField="DepID" Display="False" HeaderText="UniqueNumber1" 
                    ReadOnly="True" UniqueName="DepID">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" UniqueName="Contact1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="EXT" HeaderText="Ext" UniqueName="Ext1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP1">  
                </radG:GridBoundColumn> 
            </Columns> 
            <ParentTableRelation> 
                <radG:GridRelationFields DetailKeyField="DepID" MasterKeyField="ContactID" /> 
            </ParentTableRelation> 
        </radG:GridTableView> 
    </DetailTables> 
</MasterTableView> 
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">  
        </ClientSettings> 
</radg:radgrid> 
And here is the vb code behind.
    Protected Sub dgDep_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles dgDep.ItemDataBound  
        'If TypeOf e.Item Is GridDataItem Then  
        If TypeOf e.Item Is GridDataItem AndAlso (e.Item.OwnerTableView Is dgDep.MasterTableView) Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim strChk As String = item.GetDataKeyValue("ContactIndic").ToString()  
            Dim chkbx As CheckBox = DirectCast(item("ContactIndic").FindControl("cbIndic"), CheckBox)  
            Dim DepID As String = item.GetDataKeyValue("ContactID").ToString()  
            If strChk = "1" Then 
                chkbx.Checked = True 
            Else 
                chkbx.Checked = False 
            End If 
 
            Dim getDS2 As New DataSet  
            getDS2 = dataConn.PhoneGetEachDep(DepID)  
            dgDep.MasterTableView.DetailTables.Item(0).DataSource = getDS2  
 
        End If 
    End Sub 
 
    Protected Sub dgDep_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles dgDep.NeedDataSource  
        Dim getDS As New DataSet  
        getDS = dataConn.AllDep()  
        dgDep.DataSource = getDS.Tables(0).DefaultView  
    End Sub 

Thank you very much,
Shehab
Shinu
Top achievements
Rank 2
 answered on 20 May 2008
1 answer
132 views
Hi all,

I am trying to bind the grid in the code behind and also the Hierarchy table with the code behind, I searched in the documentation but couldn't really get to a solution. If you could please direct me to the right spot in the documentation or video or let me know what I am doing wrong, I would really appreciate your help.

Here is my HTML
<radg:radgrid id="dgDep" runat="server" allowsorting="True" 
        autogeneratecolumns="False" gridlines="None" Width="689px" Skin="WebBlue">  
<MasterTableView DataKeyNames="ContactID,ContactIndic" HierarchyLoadMode="Client">  
 
    <Columns> 
      <radG:GridBoundColumn DataField="ContactID" Display="False" HeaderText="UniqueNumber" 
            ReadOnly="True" UniqueName="UniqueNumber, ContactIndic">  
      </radG:GridBoundColumn> 
      <radG:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn1">  
      </radG:GridEditCommandColumn> 
      <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" ReadOnly="True" 
            UniqueName="Contact">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Ext" HeaderText="Extension" ReadOnly="True" 
            UniqueName="Ext">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="Fax" HeaderText="Fax" UniqueName="Fax">  
      </radG:GridBoundColumn> 
      <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP">  
      </radG:GridBoundColumn> 
      <radG:GridTemplateColumn DataField="ContactIndic" HeaderText="Live" UniqueName="ContactIndic">  
        <ItemTemplate> 
            <asp:CheckBox ID="cbIndic" runat="server" Enabled="false" /> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:CheckBox ID="EditLive" runat="server" Checked='<%# Bind("ContactIndic")%>' /> 
        </EditItemTemplate> 
      </radG:GridTemplateColumn> 
 
    </Columns> 
      
    <RowIndicatorColumn Visible="False">  
        <HeaderStyle Width="20px" /> 
    </RowIndicatorColumn> 
    <ExpandCollapseColumn> 
        <HeaderStyle Width="19px" /> 
    </ExpandCollapseColumn> 
    <DetailTables> 
        <radG:GridTableView runat="server" HierarchyLoadMode="ServerBind">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False">  
                <HeaderStyle Width="19px" /> 
            </ExpandCollapseColumn> 
            <Columns> 
                <radG:GridBoundColumn DataField="DepID" Display="False" HeaderText="UniqueNumber1" 
                    ReadOnly="True" UniqueName="DepID">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Contact" HeaderText="Contact" UniqueName="Contact1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="EXT" HeaderText="Ext" UniqueName="Ext1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Pager" HeaderText="Pager" UniqueName="Pager1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="Office" HeaderText="Office" UniqueName="Office1">  
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="IP" HeaderText="IP" UniqueName="IP1">  
                </radG:GridBoundColumn> 
            </Columns> 
            <ParentTableRelation> 
                <radG:GridRelationFields DetailKeyField="DepID" MasterKeyField="ContactID" /> 
            </ParentTableRelation> 
        </radG:GridTableView> 
    </DetailTables> 
</MasterTableView> 
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">  
        </ClientSettings> 
</radg:radgrid> 
And here is the vb code behind.
    Protected Sub dgDep_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles dgDep.ItemDataBound  
        'If TypeOf e.Item Is GridDataItem Then  
        If TypeOf e.Item Is GridDataItem AndAlso (e.Item.OwnerTableView Is dgDep.MasterTableView) Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim strChk As String = item.GetDataKeyValue("ContactIndic").ToString()  
            Dim chkbx As CheckBox = DirectCast(item("ContactIndic").FindControl("cbIndic"), CheckBox)  
            Dim DepID As String = item.GetDataKeyValue("ContactID").ToString()  
            If strChk = "1" Then 
                chkbx.Checked = True 
            Else 
                chkbx.Checked = False 
            End If 
 
            Dim getDS2 As New DataSet  
            getDS2 = dataConn.PhoneGetEachDep(DepID)  
            dgDep.MasterTableView.DetailTables.Item(0).DataSource = getDS2  
 
        End If 
    End Sub 
 
    Protected Sub dgDep_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles dgDep.NeedDataSource  
        Dim getDS As New DataSet  
        getDS = dataConn.AllDep()  
        dgDep.DataSource = getDS.Tables(0).DefaultView  
    End Sub 

Thank you very much,
Shehab
Shinu
Top achievements
Rank 2
 answered on 20 May 2008
1 answer
130 views
Hello !

 I try to display into a radGrid some fields from a table. It works only with aspGridView... I suppose that I make some mistakes. Here is my code :

<telerik:RadGrid ID="rgBookingTables" runat="server" AllowPaging="true"
                AllowSorting="true" AutoGenerateColumns="false" PageSize="15" Skin="Web20">
                    <MasterTableView DataKeyNames="BookingID">
                        <DetailTables>
                            <telerik:GridTableView runat="server">
                                <Columns>
                                    <telerik:GridBoundColumn HeaderText="Booking no" DataField="BookingID" Visible="true" ReadOnly="true"></telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                    </MasterTableView>
                </telerik:RadGrid>

 rgBookingTables.DataSource = db.BookingTables;
        rgBookingTables.DataBind();


Thanks !
Shinu
Top achievements
Rank 2
 answered on 20 May 2008
3 answers
118 views
Hi guys,

I am fairly new to Telerik controls. I have implemented a grid using one of the examples given on the website. But even though I have used the RadAjaxManager using the code below:

<telerik:RadAjaxManager ID="RadAjaxManager_Bank" runat="server">
                                        <AjaxSettings >
                                            <telerik:AjaxSetting AjaxControlID="RadGrid_Bank">
                                                <UpdatedControls>
                                                    <telerik:AjaxUpdatedControl ControlID="RadGrid_Bank" LoadingPanelID="RadAjaxLoadingPanel_Bank" />
                                                </UpdatedControls>
                                            </telerik:AjaxSetting>
                                        </AjaxSettings>
                                    </telerik:RadAjaxManager>
                                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel_Bank" runat="server" Height="75px"
                                        Width="75px">
                                        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'
                                            style="border: 0px;" />
                                    </telerik:RadAjaxLoadingPanel>
                                    <telerik:RadGrid ID="RadGrid_Bank" runat="server" PageSize="5"
                                                    AllowPaging="True"
                                                    AllowFilteringByColumn="True" AllowSorting="True" GridLines="Both"
                                                    ShowGroupPanel="True" Skin="Vista" AutoGenerateColumns="false">
</telerik:RadGrid>

I still get to see sort of an update going on the grid (I wont call it refresh) if I try an activity like sorting etc.
So if I sort, the grid just flashes out from the page (without page refresh), and I can see the Loading Panel in progress, and once processing (loading) is finished, it resumes to the normal state.
What I want is to do what is provided on the website. To let the loading panel come on top of the grid and the grid not to flash out and come back on the screen.

Regards
Siddharth
Top achievements
Rank 1
 answered on 20 May 2008
6 answers
350 views
Hello,

I try to figure this out, but didn't find a solution for this.
I have a timer in my application, that do a regular check for updated data in the database.
If the data is updated there are four radgrids that need to be updated.
This timer is ajaxfied with the RadAjaxManager, and has the four radgrids as UpdatedControls.
This works ok, but i want a final touch to have it perfect.

Now, when the data is not updated, the radgrids dont't load data, but are still refreshing on the page, and the loading label is shows also.
What i want, is that when there is no data updated, the ajaxrequest is canceled, and nothing happens with the radgrids.
But i can't find a way to cancel the ajaxrequest in the server side timer event.

Or is there another way to do this?.

Thanks

Marco
Top achievements
Rank 1
 answered on 20 May 2008
10 answers
440 views
Hello,

I must be missing something, because with all the searching I have done, i cannot seem to find what code I must set in my new window, so that I can return a specified value to the origin.

I am creating a popup where a user will create a serial number AND/OR set a serial number. I am just trying to figure out how, when the window is closed, I specify the variable returned.

Thanks!
Darryl Barney
Top achievements
Rank 1
 answered on 19 May 2008
2 answers
277 views
I am trying to reorder items with drag/drop - but e.DestDataItem is null in my RadGrid1_RowDrop event and I can't figure out why.

The example works for me (e.DestDataItem is not null), but I can't tell what the difference is between my code and the example.  If someone could help me out I would greatly appreciate it.

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.Configuration;  
using System.Data;  
using Telerik.Web.UI;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using NewMillennium;  
using NewMillennium.DataAccess;  
 
public partial class Admin_UserControls_OrderFields : MillenniumUserControl  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadGrid1.Skin = Common.GridSkin;  
        if (!Page.IsPostBack)  
        {  
            WebProgramFieldSessionData.ClearSessionData();  
            RefreshGrid();  
        }  
    }  
 
    private void RefreshGrid()  
    {  
        RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;  
        RadGrid1.DataSource = WebProgramFieldSessionData.GetWebProgramFields(ProjectProgramID);  
        RadGrid1.Rebind();  
        EditAllRows();  
    }  
 
    protected void EditAllRows()  
    {  
        foreach (GridDataItem item in RadGrid1.Items)  
            item.Edit = true;  
        RadGrid1.Rebind();  
    }  
 
 
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
        RadGrid1.DataSource = WebProgramFieldSessionData.GetWebProgramFields(ProjectProgramID);  
    }  
 
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "Refresh")  
        {  
            SaveChangesInSession();  
        }  
    }  
 
    public void SaveChangesInSession()  
    {  
        foreach (GridItem item in RadGrid1.Items)  
        {  
            if (item is GridDataItem && item.IsInEditMode)  
            {  
                GridDataItem gridDataItem = item as GridDataItem;  
                int index = gridDataItem.DataSetIndex;  
                WebProgramField field = new WebProgramField(WebProgramFieldSessionData.WebProgramFields.Rows[index]);  
                field.FieldLabel = (gridDataItem["FieldLabel"].Controls[1] as TextBox).Text;  
                field.SortOrder = Convert.ToInt32((gridDataItem["SortOrder"].Controls[1] as TextBox).Text);  
                field.Visible = (gridDataItem["Visible"].Controls[0] as CheckBox).Checked;  
                field.Required = (gridDataItem["Required"].Controls[0] as CheckBox).Checked;  
                WebProgramFieldSessionData.Update(gridDataItem.DataSetIndex, field);  
            }  
        }  
        WebProgramFieldSessionData.UpdateSortOrder();  
        RefreshGrid();  
    }  
 
    public void SaveChangesInDatabase()  
    {  
        WebProgramFieldSessionData.SaveChangesInDatabase();  
    }  
 
    protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)  
    {  
        if (string.IsNullOrEmpty(e.HtmlElement))  
        {  
            if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == RadGrid1.ClientID)  
            {  
                //TODO: do stuff here  
            }  
        }  
    }  
 
    private int ProjectProgramID  
    {  
        get 
        {  
            try 
            {  
                return Convert.ToInt32(Request.QueryString["ProjectProgramID"]);  
            }  
            catch 
            {  
                throw new ArgumentException("WebProgramFields.ascx requires a valid ProjectProgramID in the querystring.");  
            }  
        }  
    }  
}  
 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebProgramFields.ascx.cs" 
    Inherits="Admin_UserControls_OrderFields" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<asp:Label runat="server" ID="lblTitle"></asp:Label> 
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowSorting="False" 
    AutoGenerateColumns="False" AllowMultiRowEdit="true" AllowMultiRowSelection="true" 
    OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" 
    OnRowDrop="RadGrid1_RowDrop">  
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
    <ClientSettings AllowRowsDragDrop="True">  
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" /> 
    </ClientSettings> 
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="FieldID" AutoGenerateColumns="False">  
        <CommandItemTemplate> 
            <div style="padding-bottom: 8px">  
                <asp:LinkButton ID="RefreshButton" runat="server" CommandName="Refresh" OnClientClick="suppressConfirmation()"><img class="middle" alt="" src="../Images/Telerik/Refresh.gif" /> Refresh&nbsp;</asp:LinkButton> 
            </div> 
        </CommandItemTemplate> 
        <Columns> 
            <telerik:GridBoundColumn SortExpression="DefaultFieldLabel" HeaderText="Field Label" 
                HeaderButtonType="TextButton" DataField="DefaultFieldLabel" ReadOnly="true">  
                <HeaderStyle HorizontalAlign="Left" /> 
            </telerik:GridBoundColumn> 
            <telerik:GridCheckBoxColumn SortExpression="FieldVisible" HeaderText="Visible" HeaderButtonType="TextButton" 
                DataField="FieldVisible" UniqueName="Visible" DataType="System.Boolean">  
                <HeaderStyle Width="50px" HorizontalAlign="center" /> 
                <ItemStyle HorizontalAlign="center" /> 
            </telerik:GridCheckBoxColumn> 
            <telerik:GridCheckBoxColumn SortExpression="FieldRequired" HeaderText="Required" 
                HeaderButtonType="TextButton" DataField="FieldRequired" UniqueName="Required" 
                DataType="System.Boolean">  
                <HeaderStyle Width="50px" HorizontalAlign="center" /> 
                <ItemStyle HorizontalAlign="center" /> 
            </telerik:GridCheckBoxColumn> 
            <telerik:GridTemplateColumn SortExpression="SortOrder" HeaderText="Sort Order" HeaderButtonType="TextButton" 
                DataField="SortOrder" UniqueName="SortOrder">  
                <HeaderStyle HorizontalAlign="center" /> 
                <ItemStyle HorizontalAlign="center" Width="80px" /> 
                <ItemTemplate> 
                    <asp:TextBox ID="SortOrder" runat="server" Width="80px" Text='<%# Bind("SortOrder") %>'></asp:TextBox> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridTemplateColumn SortExpression="FieldLabel" HeaderText="Alternate Field Label" 
                HeaderButtonType="TextButton" DataField="FieldLabel" UniqueName="FieldLabel">  
                <HeaderStyle HorizontalAlign="center" /> 
                <ItemStyle HorizontalAlign="center" Width="80px" /> 
                <ItemTemplate> 
                    <asp:TextBox ID="FieldLabel" runat="server" Width="200px" Text='<%# Bind("FieldLabel") %>'></asp:TextBox> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 
 
    public class WebProgramFieldSessionData  
    {  
        public static DataTable GetWebProgramFields(int projectProgramID)  
        {  
            ProjectProgramID = projectProgramID;  
            return WebProgramFields;  
        }  
 
        public static void ClearSessionData()  
        {  
            System.Web.HttpContext.Current.Session["WebProgramFields"] = null;  
            System.Web.HttpContext.Current.Session["WebProgramFields_ProjectProgramID"] = null;  
        }  
 
        public static DataTable WebProgramFields  
        {  
            get 
            {  
                try 
                {  
                    if (System.Web.HttpContext.Current.Session["WebProgramFields"] != null)  
                    {  
                        return System.Web.HttpContext.Current.Session["WebProgramFields"] as DataTable;  
                    }  
                    else 
                    {  
                        DataTable t = WebProgramField.GetWebProgramFieldSettingsAsDataTable(ProjectProgramID);  
                        System.Web.HttpContext.Current.Session["WebProgramFields"] = t;  
                        return t;  
                    }  
                }  
                catch (Exception ex)  
                {  
                    throw new ApplicationException("The web program fields could not be initialized because of an error: " + ex.Message);  
                }  
            }  
        }  
 
        public static int ProjectProgramID  
        {  
            get 
            {  
                if (System.Web.HttpContext.Current.Session["WebProgramFields_ProjectProgramID"] == null)  
                    System.Web.HttpContext.Current.Session["WebProgramFields_ProjectProgramID"] = 0;  
                return Convert.ToInt32(System.Web.HttpContext.Current.Session["WebProgramFields_ProjectProgramID"]);  
            }  
            set 
            {  
                System.Web.HttpContext.Current.Session["WebProgramFields_ProjectProgramID"] = value;  
            }  
        }  
 
        /// <summary>  
        /// Updates a row in session (not in the database).  
        /// </summary>  
        public static void Update(int index, WebProgramField field)  
        {  
            DataRow row = WebProgramFields.Rows[index];  
            row["FieldLabel"] = field.FieldLabel;  
            row["SortOrder"] = field.SortOrder;  
            row["FieldVisible"] = field.Visible;  
            row["FieldRequired"] = field.Required;  
        }  
 
        /// <summary>  
        /// Corrects the sort order for all items in session.  
        /// This method does not save anything in the database.  
        /// </summary>  
        public static void UpdateSortOrder()  
        {  
            WebProgramFields.DefaultView.Sort = "SortOrder asc";  
            int counter = 1;  
            foreach (DataRowView row in WebProgramFields.DefaultView)  
            {  
                row["SortOrder"] = counter;  
                counter++;  
            }  
        }  
 
        public static void SaveChangesInDatabase()  
        {  
            foreach (DataRow row in WebProgramFields.Rows)  
            {  
                WebProgramField field = new WebProgramField(row);  
                field.Save();  
            }  
        }  
    } 

Adam Nelson
Top achievements
Rank 2
 answered on 19 May 2008
Narrow your results
Selected tags
Tags
+? more
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?