Telerik Forums
UI for ASP.NET AJAX Forum
5 answers
248 views
I have a grid using the Batch edit mode.  I have a need to use a multi-select ListBox as the editor for a particular column and to bind it using data from the server (in code-behind, not a front-end SQLDataSource, etc) and then pre-select items if they match information coming from the database.  How?  In previous grids, I could use ItemDataBound to preload the ListBox.  However, batch mode was a lot of work building client side code to handle multiple edits.  I'm wanting to use your new batch mode, but...

I have tried to read/understand and follow the information here and here.

I have tried all manner of the following in the PreRender method, but cannot get a hold of the listbox...
<telerik:GridTemplateColumn DataField="MyDataField" HeaderText="My Header" UniqueName="MyUniqueName">
    <ItemTemplate>
        <%# Eval("MyBoundItem") %>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadListBox ID="MyRadListBox" runat="server" SelectionMode="Multiple" />
    </EditItemTemplate>
</telerik:GridTemplateColumn>

GridTableView masterTable = (sender as RadGrid).MasterTableView;
RadListBox myRadListBox = masterTable.GetBatchColumnEditor("MyRadListBox") as RadListBox; // Suspicious Bind & null being returned
myRadListBox.DataSource = myDataSource;
myRadListBox.DataBind();

How do I go about getting a hold of the ListBox, populate it from code-behind, and select the items in it based on values from the database?  Is this possible?
krishna
Top achievements
Rank 1
 answered on 06 Oct 2015
2 answers
118 views

Our solution is looking to clone items from a master list into a new list. We have this working on the server side but would like to move it client side if it is possible so we can prevent round trips taken. 

protected void HandleDrop(object sender, RadTreeNodeDragDropEventArgs e)
 {
     RadTreeNode sourceNode = e.SourceDragNode;
     RadTreeNode destNode = e.DestDragNode;
     RadTreeViewDropPosition dropPosition = e.DropPosition;
     //var currentlesson = sourceNode.Value;
     //RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
 
     if (destNode != null)
     {
 
         if (sourceNode.TreeView.SelectedNodes.Count <= 1)
         {
             var currentlesson = sourceNode.Value;
             RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
             //this checks if node already exists in new list
             if (foundNode == null)
             {
                 int? index = PerformDragAndDrop(dropPosition, sourceNode, destNode);
 
                 if (index != null)
                 {
                     //Console.Error.WriteLine("NodeDrop: " + e.SourceDragNode.Text + " to " + e.DestDragNode.Text);
                     //var currentindex = e.SourceDragNode.Index;
                     var currentindex = index;
                     var objectid = e.SourceDragNode.Value;
                     var parentid = destNode.Value;
                     var parentid2 = "Newlist";
                     var action = "moved";
                     if (parentid.Contains("LN"))
                     {
                         EventMovement.Add(action + currentindex + "," + objectid + "," + parentid2);
                         result.Text += action + "," + currentindex + "," + objectid + "," + parentid2 + Environment.NewLine;
                     }
                     else
                     {
                         EventMovement.Add(action + currentindex + "," + objectid + "," + parentid);
                         result.Text += action + "," + currentindex + "," + objectid + "," + parentid + Environment.NewLine;
                     }
                 }
             }
 
         }
         else if (sourceNode.TreeView.SelectedNodes.Count > 1)
         {
             int? index = PerformDragAndDrop(dropPosition, sourceNode, destNode);
 
             if (index != null)
             {
                 foreach (RadTreeNode currentNode in sourceNode.TreeView.SelectedNodes)
                 {
                     var currentlesson = currentNode.Value;
                     RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
                     //this checks if node already exists in new list
                     if (foundNode == null)
                     {
                         PerformDragAndDrop(dropPosition, currentNode, destNode);
                         //Console.Error.WriteLine("NodeDrop: " + currentNode.Text + " to " + e.DestDragNode.Text);
                         var currentindex = index;
                         var objectid = currentNode.Value;
                         var parentid = destNode.Value;
                         var action = "group-moved";
                         EventMovement.Add(currentindex + "," + objectid + "," + parentid);
                         result.Text += action + "," + currentindex + "," + objectid + "," + parentid + Environment.NewLine;
                     }
                 }
             }
         }
         destNode.Expanded = true;
     }
 }
 private int? PerformDragAndDrop(RadTreeViewDropPosition dropPosition, RadTreeNode sourceNode, RadTreeNode destNode)
 {
     int? index = null;
 
     if (sourceNode.Equals(destNode) || sourceNode.IsAncestorOf(destNode))
     {
         return null;
     }
     // clone the sourceNode
     List<RadTreeNode> sourceNodeClone = CloneNode(sourceNode);
     if (remove == false)
     {
         sourceNode.Owner.Nodes.Remove(sourceNode);
     }
     // add source node as a child of the destination node
     //if (!sourceNode.IsAncestorOf(destNode))
     //{
     //    destNode.Nodes.Add(sourceNodeClone);
     //    sourceNodeClone.AllowDrop = false;
     //}
 
     // this prevents items from being added as children when moved
     switch (dropPosition)
     {
         case RadTreeViewDropPosition.Over:
             // child
             if (!sourceNode.IsAncestorOf(destNode))
             {
                 foreach (RadTreeNode node in sourceNodeClone)
                     destNode.Nodes.Add(node);
 
             }
             break;
 
         case RadTreeViewDropPosition.Above:
             // sibling - above                   
             foreach (RadTreeNode node in sourceNodeClone)
                 destNode.InsertBefore(node);
             break;
 
         case RadTreeViewDropPosition.Below:
             // sibling - below
             foreach (RadTreeNode node in sourceNodeClone)
                 destNode.InsertAfter(node);
             break;
     }
     var currentlesson = sourceNode.Value;
     RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
     if (foundNode != null)
     {
         index = foundNode.Index;
     }
     return index;
 }
 private List<RadTreeNode> CloneNode(RadTreeNode sourceNode)
 {
 
     List<RadTreeNode> clonedNode = new List<RadTreeNode>();
     RadTreeNode clone = new RadTreeNode();
     clone.Text = sourceNode.Text;
     clone.Value = sourceNode.Value;
     clone.ImageUrl = sourceNode.ImageUrl;
     clone.ExpandedImageUrl = sourceNode.ExpandedImageUrl;
     clone.AllowDrop = sourceNode.AllowDrop; //this carries over the allow drop from the main list
 
     //check if parent node -- for each statement didnt work here
     if (sourceNode.ParentNode != null)
     {
         if (sourceNode.Nodes.Count > 0)
         {
             //grab and move children too
             for (int i = 0; i < sourceNode.Nodes.Count - 1; i++)
             {
                 clone.Nodes.Add(sourceNode.Nodes[i]);
             }
 
 
         }
     }
     clonedNode.Add(clone);
     return clonedNode;
 }

Alice
Top achievements
Rank 1
 answered on 06 Oct 2015
5 answers
288 views
The online examples and documentation seem to suggest that <TAB> and <Shift-TAB> keys can be used to move between tabs in the tab strip control.

So far I've been unable to that, even with the posted online example. I'm testing for 508 compliance, so this is critical. I was able to change the tabs using access keys, but not the <tab> key.

My page looks like this.

 

 

<telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="0" MultiPageID="RadMultiPage1" ShowBaseLine="true">

 

 

 

<Tabs>

 

 

 

<telerik:RadTab runat="server" Selected="True" Text="<u>T</u>ables" AccessKey="T">

 

 

 

</telerik:RadTab>

 

 

 

<telerik:RadTab runat="server" Text="<u>P</u>arameters" AccessKey="P">

 

 

 

</telerik:RadTab>

 

 

 

</Tabs>

 

 

 

</telerik:RadTabStrip>

 

 

 

<telerik:RadMultiPage ID="RadMultiPage1" Runat="server" SelectedIndex="0">

 

 

 

<telerik:RadPageView id="RadPageView1" runat="server" Selected="true">

 

Table List

 

 

</telerik:RadPageView>

 

 

 

<telerik:RadPageView id="RadPageView2" runat="server">

 

Parameter List

 

 

</telerik:RadPageView>

 

 

 

</telerik:RadMultiPage>


Am I missing something or is this feature (use of <TAB> key) not supported?

/Stan

 

Nencho
Telerik team
 answered on 06 Oct 2015
2 answers
67 views

Hello,

I'm using a RadGrid with dynamic columns and column filtering. I'm also setting a filter template for the columns I want to have this feature. Everything is working fine except for one thing I'm trying.

When I send the filter command on the client-side: 

1.tableView.filter(columnUnique, searchValue, condition);

I also set a css class on an element of my template.

I see this element changing but when the filter command is completed, it's gone.

Well, I implemented so far:

- The columns on the grid are defined during the page_init

- During this initialization, I set the filter templates too

This is an example of one of my templates:

01.           public TextTemplate(Page _page, RadGrid _grid, RadContextMenu _menu, GridColumnSetting _column)
02.        {
03.            page = _page;
04.            grid = _grid;
05.            menu = _menu;
06.            columnSettings = _column;
07. 
08.            panel = (Panel)page.LoadControl(typeof(Panel), null);
09.            panel.ID = "ftrPnl_text_" + columnSettings.DataMember;
10.            panel.CssClass = "ftrPnl";
11. 
12.            panel2 = (Panel)page.LoadControl(typeof(Panel), null);
13.            panel2.ID = "ftrIpt_text_" + columnSettings.DataMember;
14.            panel2.CssClass = "ftrIpt";
15. 
16.            textBox = (CustomTextBox)page.LoadControl("~/Controls/CustomTextBox.ascx");
17.            textBox.ID = "txt0_" + columnSettings.DataMember;
18.            textBox.ToolTip = columnSettings.ColumnToolTip;
19. 
20.            button = (Button)page.LoadControl(typeof(Button), null);
21.            button.ID = "btn_filter_" + columnSettings.DataMember;
22.            button.UseSubmitBehavior = false;
23.            button.CssClass = "ftrTxt rgFilter btn_filter";
24. 
25.            hidden = (HiddenField)page.LoadControl(typeof(HiddenField), null);
26.            hidden.ID = "hdn_filter_" + columnSettings.DataMember;
27.        }
28. 
29.        public void InstantiateIn(Control container)
30.        {
31.            textBox.OnClientKeyDown =
32.                "filterOnEnter('" + hidden.ID + "', 'text', '" + button.ID + "');";
33. 
34.            hidden.Value =
35.                grid.ClientID + FLP.SEPPROP +
36.                columnSettings.DataMember + FLP.SEPPROP +
37.                textBox.ClientID + FLP.SEPPROP +
38.                columnSettings.FilterFunction.AsString();
39. 
40.            button.OnClientClick = FilterButtonJS();
41. 
42.            panel2.Controls.Add(textBox);
43.            panel.Controls.Add(panel2);
44.            panel.Controls.Add(button);
45. 
46.            container.Controls.Add(panel);
47.            container.Controls.Add(hidden);
48.        }

Eyup
Telerik team
 answered on 06 Oct 2015
1 answer
90 views

I would like to change the cell color of a specific cell in a specific row defined by two datakey values. For example using the following Grid:

Type     ID    Adjustments
PG        1            $10.00
V3         1            $10.00
PG        2            $134.35
V3         2            $178.60

I would like to change the background of the cells in the Adjustments column for the cells with values $134.35 and $178.60 based on the Type = PG and ID = 2 and the Type = V3 and the ID = 2. Might even get away with simply the ID = 2.

 

I attempted:

 

Protected Sub rgd_Paycheck_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_Paycheck.ItemCreated
 
        For Each item As GridDataItem In rgd_Paycheck.MasterTableView.Items
            Dim keyrow_PGPayrollID As String = item.GetDataKeyValue("PGPayrollID").ToString()
            Dim keyrow_RECTYPE As String = item.GetDataKeyValue("RECTYPE").ToString()
 
            If keyrow_PGPayrollID = 2 And keyrow_RECTYPE Like "PG" Then
 
                Dim TotalAdjustments_PG As String = item("TotalAdjustments").Text
                Session("TotalAdjustments_PG") = TotalAdjustments_PG
            End If
 
            If keyrow_PGPayrollID = 2 And keyrow_RECTYPE Like "V3" Then
 
                Dim TotalAdjustments_V3 As String = item("TotalAdjustments").Text
                Session("TotalAdjustments_V3") = TotalAdjustments_V3
            End If
 
            If Session("TotalAdjustments_PG") <> Session("TotalAdjustments_V3") Then
                Label1.Text = "OOPS"
 
                If (TypeOf (e.Item) Is GridDataItem) Then
                    'Get the instance of the right type
                    Dim dataBoundItem As GridDataItem = e.Item
 
                    'Check the formatting condition
                    If keyrow_RECTYPE = "PG" Then
                        dataBoundItem("TotalAdjustments").ForeColor = Color.Red
                        dataBoundItem("TotalAdjustments").Font.Bold = True
                        'Customize more...
                    End If
                End If
 
            End If
 
        Next
 
    End Sub

 And attempted:

 

Protected Sub rgd_Paycheck_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_Paycheck.ItemDataBound
 
    If TypeOf e.Item Is GridDataItem Then
 
        Dim dataBoundItem As GridDataItem = DirectCast(e.Item, GridDataItem)
 
        If dataBoundItem.GetDataKeyValue("PGPayrollID").ToString() = "PG" And dataBoundItem.GetDataKeyValue("RECTYPE").ToString() = "V3" Then
            dataBoundItem("TotalAdjustments").ForeColor = Color.Red
            dataBoundItem("TotalAdjustments").Font.Bold = True
        End If
 
    End If
 
End Sub

As always, any assistance much appreciated.

Allan

 

Eyup
Telerik team
 answered on 06 Oct 2015
10 answers
249 views

Hello everyone,




I have a little problem I have on left hand side of RadGrid  textboxes and search button... on the right hand side I have a Rad grid that been loaded with info from DB... my question after filling the text boxes with info to search I want to allow on key press enter instead of the user click to search data in the radgrid  how can I do this??



***************************************aspx filter code*****************************************



<telerik:RadPanelBar runat="server" ID="rpbMainMenu" Width="248px" Height="517px" ExpandMode="FullExpandedItem" >

    <Items>                     

          <telerik:RadPanelItem  Expanded="True"  ImageUrl="../Images/Layout/phone_edited.png"  Text="Phone Book Search">                                      

                    <ContentTemplate>

                    <div style=" border:0px solid red; padding:20px 0px 0px 10px">

                    <table class="filtersTable">

                         <tr>

                            <td>Contact Type:</td>

                            <td><telerik:RadComboBox runat="server" CheckBoxes="true" ID="rcbFilterPersonType" EmptyMessage="Select Person Type" Enabled="True"></telerik:RadComboBox></td>

                        </tr>

                        <tr>

                            <td>First Name:</td>

                            <td><asp:TextBox ID="txtFilterFirstName" runat="server" MaxLength="50"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td>Last Name:</td>

                            <td><asp:TextBox ID="txtFilterLastName" runat="server" MaxLength="50"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td>Company:</td>

                            <td><asp:TextBox ID="txtFilterCompany" runat="server" MaxLength="25"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td>Email:</td>

                            <td><asp:TextBox ID="txtFilterEmail" runat="server" MaxLength="50"></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td>Cell Phone:</td>

                            <td> <asp:TextBox id="txtFilterCellPhone" runat="server" MaxLength="50" ></asp:TextBox></td>

                        </tr>

                        <tr>

                            <td>&nbsp;</td>

                            <td>

                                <telerik:RadButton ID="pSearchBtn" runat="server" Text="Search" Style="display: block; width: 80px;" AutoPostBack="true" OnClick="GeneralSearchBtn_Click" Font-Bold="False" ButtonType="SkinnedButton">

                                    <Icon PrimaryIconCssClass="rbSearch" PrimaryIconLeft="4" PrimaryIconTop="4"></Icon>

                                </telerik:RadButton>

                            </td>

                        </tr>

                        </tr>

                    </table>

                    </div>

    </ContentTemplate>

</telerik:RadPanelItem>

</Items>

</telerik:RadPanelBar>





*******aspx rad grid*******************

 <telerik:RadGrid

            ID="rgPhoneBook"

            runat="server" 

            Width="100%" 

            AutoGenerateColumns="False"

            AllowPaging="True"

            AllowSorting="True"

            PageSize="20"

            CellSpacing="0" GridLines="None" Height="100%"

            OnItemCommand="rgPhoneBook_ItemCommand"

            OnPageIndexChanged="rgPhoneBook_OnPageIndexChanged"

            OnSortCommand="rgPhoneBook_OnSortCommand"

            EnableHeaderContextFilterMenu="False">

            <ClientSettings>

                <Selecting AllowRowSelect="True" />

                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2" ScrollHeight="380px"/>

            </ClientSettings>

            <PagerStyle Mode="NumericPages"></PagerStyle>

            <MasterTableView ShowHeadersWhenNoRecords="true"  Font-Size="11px" GridLines="None" AllowPaging="True" CommandItemDisplay="Top" AllowAutomaticUpdates="False" TableLayout="Fixed">

                <Columns>

                      <telerik:GridBoundColumn DataField="PersonID" Display="false"/>

                      <telerik:GridTemplateColumn HeaderText="First Name" HeaderStyle-Width="120px"  SortExpression="FirstName">

                        <ItemTemplate>

                             <%# RenderActiveUser(DataBinder.Eval(Container.DataItem, "Active"))%> &nbsp; <%# DataBinder.Eval(Container.DataItem, "FirstName")%>

                        </ItemTemplate>

                      </telerik:GridTemplateColumn>

                      <telerik:GridBoundColumn HeaderText="Last Name" HeaderStyle-Width="120px" ItemStyle-Width="130px" DataField="LastName" ShowFilterIcon="false" SortExpression="LastName" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"/>

                      <telerik:GridBoundColumn HeaderText="Company" HeaderStyle-Width="80px" ItemStyle-Width="130px" DataField="Company" ShowFilterIcon="false" SortExpression="Company" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"/>

                      <telerik:GridBoundColumn HeaderText="Email" HeaderStyle-Width="150px" ItemStyle-Width="70px" DataField="Email" ShowFilterIcon="false" SortExpression="Email" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"/>

                      <telerik:GridBoundColumn HeaderText="Mobile Phone" HeaderStyle-Width="120px" ItemStyle-HorizontalAlign="Left" DataField="CellNum" ShowFilterIcon="false" SortExpression="CellNum" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"/>

                      <telerik:GridBoundColumn HeaderText="Person Type" HeaderStyle-Width="130px" ItemStyle-HorizontalAlign="Left" DataField="PeopleType" ShowFilterIcon="false" SortExpression="PeopleType" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"/>

                      <telerik:GridTemplateColumn HeaderText="Edit"  HeaderStyle-Width="70px">

                          <ItemTemplate>                           

                                 <%# GenerateEditLink(DataBinder.Eval(Container.DataItem, "PersonID"))%>                             

                          </ItemTemplate>

                      </telerik:GridTemplateColumn>

                       </Columns>

                <CommandItemTemplate>

                 <div style="padding: 5px 5px;">

                    <table class="rcCommandTable" width="100%">

                        <td>

                            <asp:LinkButton ID="lbAddNewPerson" runat="server" CssClass="rgAdd" Width="20" Height="20"  OnClientClick="Javascript:return showDialogInitially();"  ></asp:LinkButton> Add New Person

                        </td>

                     </table>

                </div>

                </CommandItemTemplate>

            </MasterTableView>

        </telerik:RadGrid>

        </div>

    </ContentTemplate>

</asp:UpdatePanel>







Eyup
Telerik team
 answered on 06 Oct 2015
3 answers
124 views
​I am using Telerik Rad Scheduler in ​my application,
I have set RenderMode to "Auto" as need to make page adaptive in mobile devices
but is not working.

Also ​i have added reference to Telerik.Web.Device.Detection.dll and added it as namespace in code file (using Telerik.Web.Device.Detection;  )
and ​added this meta tag in master page
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">

so if ​i​ am missing any property or configuration to make radscheduler adaptive in mobile?
Dimitar
Telerik team
 answered on 06 Oct 2015
1 answer
33 views
i want to string search in rad grid .the data is in hierarchy.i want to search the data till last node.please help me its urgent.
Maria Ilieva
Telerik team
 answered on 06 Oct 2015
3 answers
81 views

Help Me!

- How to Binding data to GridDropDownColumn from DataBase

- How to Insert/Update Value in Editmode for Ragird

 Thank !

 

Maria Ilieva
Telerik team
 answered on 06 Oct 2015
3 answers
233 views

Help Me!

VS2010, RadControls for ASP.NET AJAX Q3 2010. FrameWork 4.0
- How to Binding data to GridDropDownColumn from DataBase
- How to Insert/Update Value for Ragird1
 Thank !

 ASPX File

<%@ Page Language="C#" AutoEventWireup="true" validateRequest="false" enableEventValidation="false" CodeFile="HuyenThi_Datao.aspx.cs" Inherits="HuyenThi_Datao" MasterPageFile="~/AdminMasterPage.master" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<asp:Content ID="ContentHuyenThi_Datao" ContentPlaceHolderID="ContentPlaceHolder" runat="server">

    <!-- content begin -->


    <div class="qsf_content_area_wrapper">
        <div class="qsf_content_area">

                <table cellspacing="0" cellpadding="0" border="0" 
                    style="width: 95%; height: 18px;">

                  <tr>
                  <td style="width: 350px">
                  </td>
                     <td >
                        <asp:CheckBox ID="CheckBox2"  Text="Chọn tất cả các trang" runat="server" Height="22px">
                       </asp:CheckBox>
                    </td>
                    <td style="width: 120px">
                       <asp:Button ID="Button1" CssClass="button" Width="110px" Text="Export to Excel" OnClick="Button1_Click"
                          runat="server" Height="22px">
                      </asp:Button>
                    </td>
                     <td style="width: 120px">
                      <asp:Button ID="Button2" CssClass="button" Width="110px" Text="Export to Word" OnClick="Button2_Click"
                        runat="server" Height="22px">
                     </asp:Button>
                    </td>


                    <td style="width: 120px">
                       <asp:Button ID="Button3" CssClass="button" Width="110px" Text="Export to CSV" OnClick="Button3_Click"
                        runat="server" Height="22px">
                       </asp:Button>
                   </td>

                     <td style= "width:120px" >
                      <telerik:RadButton ID="RadButton3" runat="server" Width="110px" PostBackUrl="~/HuyenThi.aspx" 
                        Text="Tạo Mới" Height="22px">
                       </telerik:RadButton>
                      
                    </td>
                  </tr>
                </table>
             
    <br />

    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>


            <table cellspacing="0" cellpadding="0" border="0"  width="100%">

                <tr >

                    <td >
                        <telerik:RadButton ID="RadButton2" runat="server" Font-Bold="True" 
                            Font-Names="Times New Roman" Font-Size="XX-Large" ForeColor="#0066FF" ReadOnly="True" 
                            Text=" Huyen Thi created" Height="20px" Width="98%" 
                            EnableBrowserButtonStyle="True">
                        </telerik:RadButton>
                        
                    </td>
                </tr>
            </table>

    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
             <telerik:RadGrid Width="98%" runat="server" ID="RadGrid1" AllowPaging="True" 
                AllowSorting="True" OnDeleteCommand = "RadGrid1_DeletedCommand" 
                OnInsertCommand = "RadGrid1_InsertCommand" OnUpdateCommand= "RadGrid1_UpdateCommand"
            MasterTableView-NoMasterRecordsText="No Recorde" 
                OnNeedDataSource="RadGrid1_NeedDataSource" 
                OnSortCommand="RadGrid1_SortCommand"  
                OnPageIndexChanged="RadGrid1_PageIndexChanged" 
                OnPageSizeChanged="RadGrid1_PageSizeChanged" EnableViewState="False" 
                GridLines="None" Skin="Web20" AllowFilteringByColumn="True" PageSize="15" 
                    CellSpacing="-1">
                         
                    <MasterTableView DataKeyNames="HuyenThiId" AutoGenerateColumns="False"  EditMode="EditForms"
                    Width="100%" AdditionalDataFieldNames="HuyenThiId" AllowNaturalSort="False" 
                    EnableViewState="False" Font-Bold="False" Font-Italic="False" 
                        Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                        GridLines="None">
                         <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                         <Columns>
                          <telerik:GridEditCommandColumn HeaderText="UpDate" EditText="UpDate">
                          </telerik:GridEditCommandColumn>
                             <telerik:GridDropDownColumn UniqueName="TinhTen"  ListDataMember="TinhTen" SortExpression="TinhTen" ListTextField="TinhTen" EnableEmptyListItem="true"
                              EmptyListItemText="--Chọn Tỉnh--" EmptyListItemValue="" ListValueField="TinhId"  HeaderText="Tên Tỉnh" DataField="TinhId" >
                             </telerik:GridDropDownColumn>
                        <telerik:GridBoundColumn DataField="HuyenThiId" HeaderText="ID HuyenThiId" ReadOnly="True" SortExpression="HuyenThiId" 
                            UniqueName="HuyenThiId" Visible="false">
                            <HeaderStyle Width="20px" ForeColor="Silver" />
                            <ItemStyle ForeColor="Silver" />
                         </telerik:GridBoundColumn>
                       
                        <telerik:GridBoundColumn DataField="HuyenThiTen" HeaderText="Ten Huyen Thi" SortExpression="HuyenThiTen"
                            UniqueName="HuyenThiTen" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="HuyenThiMoTa" HeaderText="Mô Tả" SortExpression="HuyenThiMoTa"
                            UniqueName="HuyenThiMoTa" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                        </telerik:GridBoundColumn>

                        <telerik:GridHyperLinkColumn DataNavigateUrlFields="HuyenThiId" HeaderText="EDIT" DataNavigateUrlFormatString="~/HuyenThi.aspx?Id={0}" 
                            Text="<img alt='EDIT' src='images\Edit.gif' border='0' />" 
                                 UniqueName= "SuaColumn" AllowFiltering="False"> 
                            <HeaderStyle HorizontalAlign="center" />
                            <ItemStyle HorizontalAlign="Center" /> 
                        </telerik:GridHyperLinkColumn>
                        <telerik:GridButtonColumn CommandName="Delete" HeaderText="Del" ConfirmText=" Del Huyen Thi " Text="<img alt='Del' src='images\Delete.gif' border='0' />" UniqueName= "DeleteColumn" >
                            <HeaderStyle HorizontalAlign="center" />
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridButtonColumn>
                      </Columns>



                        <PagerStyle AlwaysVisible="True" />



                     </MasterTableView>



                    <FilterMenu>
                        <CollapseAnimation Type="None" />
                    </FilterMenu>


<HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Web20"></HeaderContextMenu>

           </telerik:RadGrid>

        </div>
    </div>
</asp:Content>

 ASPX.CS File

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bussiness;
using Model;
using Telerik.Web.UI;

public partial class HuyenThi_Datao : System.Web.UI.Page
{

    
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);

    }

    //Load data
    protected void LoadData()
    {
        RadGrid1.DataSource = ListHuyenThiService.SelectHuyenThiInTinhAll();
        RadGrid1.DataBind();
        
         RadGrid1.MasterTableView.GetColumn("HuyenThiTen").Display = true;
         RadGrid1.MasterTableView.GetColumn("DeleteColumn").Display = true;
         RadGrid1.MasterTableView.GetColumn("SuaColumn").Display = true;
    }



    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = ListHuyenThiService.SelectHuyenThiInTinhAll();

    }

    protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {

        // How to get Value to Update Database
    }

    protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        // How to get Value to Update Database
    }


    private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
        {
            
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditManager editMan = editedItem.EditManager;

            GridDropDownListColumnEditor editor = editMan.GetColumnEditor("TinhTen") as GridDropDownListColumnEditor;
            editor.DataSource = ListTinhService.SelectTinhAll();
            editor.DataBind();

        }
    }

    protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
    {
        LoadData();
    }

    protected void RadGrid1_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        LoadData();
    }

    protected void RadGrid1_SortCommand(object sender, Telerik.Web.UI.GridSortCommandEventArgs e)
    {
        LoadData();
    }



    protected void RadGrid1_DeletedCommand (object source, Telerik.Web.UI.GridCommandEventArgs e)

    {
        //Get the GridDataItem of the RadGrid     
        GridDataItem item = (GridDataItem)e.Item;
        //Get the primary key value using the DataKeyValue.     
        int intHuyenThiID = Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["HuyenThiId"]);
        try
        {
            HuyenThiService.DeleteHuyenThi(intHuyenThiID);

            //Insert Log
            string strDes = "Xóa Huyện Thị ID=" + intHuyenThiID;
            string strIP = HttpContext.Current.Request.UserHostAddress;
            LogService.CreateLog(Page.User.Identity.Name, strDes, DateTime.Now, strIP);
            LoadData();
        }
        catch (Exception ex)
        {
            RadGrid1.Controls.Add(new LiteralControl("Không xóa được Nhóm này."));
            e.Canceled = true;
        }
           
    }

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ConfigureExport();
        RadGrid1.MasterTableView.ExportToExcel();
    }

    protected void Button2_Click(object sender, System.EventArgs e)
    {
        ConfigureExport();
        RadGrid1.MasterTableView.ExportToWord();
    }

    protected void Button3_Click(object sender, System.EventArgs e)
    {
        ConfigureExport();
        RadGrid1.MasterTableView.ExportToCSV();
    }

    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
            e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
            e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
        {
            ConfigureExport();
        }
    }

    public void ConfigureExport()
    {
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.IgnorePaging = CheckBox2.Checked;
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.FileName = "HuyenThi_Export_" + DateTime.Now.ToString("dd.MM.yyyy");
        RadGrid1.ExportSettings.HideStructureColumns = true;
    }

}

 

 

Maria Ilieva
Telerik team
 answered on 06 Oct 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?