This is a migrated thread and some comments may be shown as answers.

Hyperlink in GridBoundColumn and updating Specific Column

8 Answers 1025 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajeev
Top achievements
Rank 1
Rajeev asked on 19 Dec 2012, 11:50 PM
I am trying to create two of my columns of telerik:GridBoundColumn as Hyperlinks. When the user clicks on the column a popup window comes with the value of the column and user can update that value. I am also using the SUM to add the columns(Price, Price2) and the Grand Total(That is sum of two columns Price, Price2).
I am able to do the SUM and the Grand Total but i am not able to make my two columns (Price and Price2) as links and when user click on the column Price or Price2 a window pops up with the value of the Column. Then the User can update the value and then it updates the SUM and the Grand Total.
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
   <telerik:RadGrid ID="RadGrid1" Width="100%" AllowSorting="True" ShowFooter="True" OnPreRender="RadGrid1_PreRender"
       PageSize="15" AllowPaging="True" OnItemDataBound="RadGrid1_ItemDataBound" AllowMultiRowSelection="True"
       ShowChooser="true" EnableLinqExpressions="False" runat="server" GridLines="None"
       AutoGenerateColumns="False" CellSpacing="0" DataSourceID="SqlDataSource1">
       <MasterTableView Width="100%" Summary="RadGrid table" RetrieveAllDataFields="false"
           DataSourceID="SqlDataSource1">
           <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
           <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
           </RowIndicatorColumn>
           <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
           </ExpandCollapseColumn>
           <Columns>
               <telerik:GridBoundColumn DataField="ProductID" HeaderText="ProductID" DataType="System.Int32"
                   SortExpression="ProductID" FilterControlAltText="Filter ProductID column" ReadOnly="True"
                   UniqueName="ProductID">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="ID" HeaderText="ID" DataType="System.Int32" FilterControlAltText="Filter ID column"
                   SortExpression="ID" UniqueName="ID">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" FilterControlAltText="Filter ProductName column"
                   SortExpression="ProductName" UniqueName="ProductName">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="Price" HeaderText="Price" SortExpression="Price" UniqueName="price">
               </telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="Price2" HeaderText="Price2" SortExpression="Price2" UniqueName=Price2>
               </telerik:GridBoundColumn>
         
           </Columns>
           <EditFormSettings>
               <EditColumn FilterControlAltText="Filter EditCommandColumn column">
               </EditColumn>
           </EditFormSettings>
       </MasterTableView>
       <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
       <FilterMenu EnableImageSprites="False">
       </FilterMenu>
   </telerik:RadGrid>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Rajeev_DBConnectionString %>"
       SelectCommand="SELECT * FROM [product]"></asp:SqlDataSource>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Telerik.Web.UI;
 
namespace Telerik_Master_Pages
{
    public partial class TestSum : System.Web.UI.Page
    {
 
        Decimal total;
        Decimal total2;
        Decimal grantotal;
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                Decimal fieldValue = Convert.ToDecimal(dataItem["Price"].Text);
                Decimal Fieldvalue2 = Convert.ToDecimal(dataItem["Price2"].Text);
 
 
                total += fieldValue;
                total2 += Fieldvalue2;
               // grantotal = fieldValue + Fieldvalue2;
            }
            if (e.Item is GridFooterItem)
            {
                grantotal = Convert.ToDecimal(total) + Convert.ToDecimal(total2);
 
                GridFooterItem footerItem = e.Item as GridFooterItem;
                footerItem["Price"].Text = "total: " + total.ToString();
 
                footerItem["Price2"].Text = "total Price2: " + total2.ToString() + "      " + " Grand Total " + grantotal;
 
                 
 
            }
 
 
           
        }
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
             
        }
 
    }
}

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Dec 2012, 09:21 AM
Hi,

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
     if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            HyperLink link = new HyperLink();
            link.NavigateUrl = "Page.aspx";
            link.Text = item["Uniquename"].Text;
            item["Uniquename"].Controls.Add(link);
        }
    }
protected
void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            HyperLink link = new HyperLink();
            link.NavigateUrl = "Page.aspx";
            link.Text = item["Uniquename"].Text;
            item["Uniquename"].Controls.Add(link);
        }
    }

Thanks,
Shinu.
0
Rajeev
Top achievements
Rank 1
answered on 20 Dec 2012, 05:01 PM
I was able to create a link using ur code.

Is there another way of doing this thing. Instead of going to a new Page(EditForm.aspx)When the user clicks on the link a window pops up with the specific cell value(Price2) in a textBox and user updates and it updates the grid with the updated numbers( Just like ur PopUP Edit Form).

Thanks Rajeev






  
if (e.Item is GridDataItem)
            {
 
                GridDataItem dataItem = e.Item as GridDataItem;
 
                GridDataItem item = (GridDataItem)e.Item;
 
                TableCell cell = dataItem["Price2"];
 
                HyperLink hyplink = new HyperLink();
                hyplink.ID = "HyperLink2";
                hyplink.Text = item["Price2"].Text;
              
                hyplink.NavigateUrl = "EditForm.aspx?CellValue=" + cell.Text;
 
                item["Price2"].Controls.Add(hyplink);
              //  hyplink.Attributes.Add("onclick", "window.radopen('EditForm.aspx','RadWindow1')");
 
            }


0
Shinu
Top achievements
Rank 2
answered on 21 Dec 2012, 04:29 AM
Hi,

Try the following javascript to achieve your scenario.

C#:
HyperLink hyplink = new HyperLink();
hyplink.ID = "HyperLink2";
hyplink.Text = item["Price2"].Text;
int index = e.Item.ItemIndex;
hyplink.Attributes.Add("onclick", "rowIndex('" + index + "');");

JS:
function rowIndex(index) {
 var grid = $find('<%= RadGrid1.ClientID %>');
 var masterTable = grid.get_masterTableView();
 var row = masterTable.get_dataItems()[index];
 var cell = masterTable.getCellByColumnUniqueName(row, "UniqueName");
 alert(cell.innerHTML);
 var wind = $find("RadWindow1");
 wind.show();
 $get("<%= txt.ClientID %>").value = cell.innerHTML;
 }

Thanks,
Shinu.
0
Rajeev
Top achievements
Rank 1
answered on 22 Dec 2012, 12:17 AM
It is still not working. I tried another approach using your Demo
 http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid

I created a Main Radgrid (TestSum2,.aspx and two Edit Pages(EditForm.aspx and EditForm2.aspx)
Now i am trying to create hyperlinks on Price and Price2. IF some clicks on Price it goes to EditForm.aspx and Price2 goes to EditForm2.aspx).

  1. With this i am not able to create hyperlinks for the columns Price and Price2 which goes to Editform.aspx and editform2.aspx
  2. How do i get rid of the Add new  record  from the top of the Grid.
  3. How do u underline the Hyperlinks Price and Price2

Your help will be really appreciated!!!
Thanks


Here is my Code
<%@ Page Title="" Language="C#" MasterPageFile="~/Telerik.Master" AutoEventWireup="true"
    CodeBehind="TestSum2.aspx.cs" Inherits="Telerik_Master_Pages.TestSum2" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentplaceholder1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
        EnableRoundedCorners="false" />
    <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("EditForm.aspx?ProductID=" + id, "UserListDialog");
                return false;
            }
 
 
            function ShowEditForm2(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("EditForm2.aspx?ProductID=" + id, "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("EditForm2.aspx?ProductID=" + eventArgs.getDataKeyValue("ProductID"), "UserListDialog");
            }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid OnItemCreated="RadGrid1_ItemCreated" ID="RadGrid1" runat="server"
        AllowPaging="True" Width="97%" DataSourceID="SqlDataSource1"
        AutoGenerateColumns="False" ShowFooter="True" OnItemDataBound="RadGrid1_ItemDataBound"
        CellSpacing="0" GridLines="None">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView DataKeyNames="ProductID" ClientDataKeyNames="ProductID" Width="100%"
            CommandItemDisplay="Top">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="ProductID" HeaderText="ProductID" DataType="System.Int32"
                    SortExpression="ProductID" FilterControlAltText="Filter ProductID column" ReadOnly="True"
                    UniqueName="ProductID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" DataType="System.Int32" FilterControlAltText="Filter ID column"
                    SortExpression="ID" UniqueName="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" FilterControlAltText="Filter ProductName column"
                    SortExpression="ProductName" UniqueName="ProductName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Price" HeaderText="Price" SortExpression="Price"
                    UniqueName="Price" DataType="System.Decimal">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Price2" HeaderText="Price2" SortExpression="Price2"
                    UniqueName="Price2" DataType="System.Decimal">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true"></Selecting>
            <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
        </ClientSettings>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Rajeev_DBConnectionString %>"
         
        SelectCommand="SELECT * FROM [Rajeev_product]">
        
    </asp:SqlDataSource>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="320px"
                Width="310px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
                Modal="true">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
</asp:Content>

Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Business;
 
namespace Telerik_Master_Pages
{
    public partial class TestSum2 : System.Web.UI.Page
    {
        Decimal total;
        Decimal total2;
        Decimal grantotal;
         protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
            //   // HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
            //   // editLink.Attributes["href"] = "#";
            //    GridDataItem item = (GridDataItem)e.Item;
            //    HyperLink hyplink = new HyperLink();
            //    hyplink.ID = "HyperLink2";
            //    hyplink.Text = item["Price"].Text;
            //    hyplink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProductID"], 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();
            }
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
 
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                Decimal fieldValue = Convert.ToDecimal(dataItem["Price"].Text);
                Decimal Fieldvalue2 = Convert.ToDecimal(dataItem["Price2"].Text);
 
 
                total += fieldValue;
                total2 += Fieldvalue2;
                // grantotal = fieldValue + Fieldvalue2;
            }
            if (e.Item is GridFooterItem)
            {
                grantotal = Convert.ToDecimal(total) + Convert.ToDecimal(total2);
 
                GridFooterItem footerItem = e.Item as GridFooterItem;
                footerItem["Price"].Text = "total: " + total.ToString();
 
                footerItem["Price2"].Text = "total Price2: " + total2.ToString() + "      " + " Grand Total " + grantotal;
 
 
 
            }
            if (e.Item is GridDataItem)
            {
 
               // GridDataItem dataItem = e.Item as GridDataItem;
 
                GridDataItem item = (GridDataItem)e.Item;
                HyperLink hyplink = new HyperLink();
                hyplink.ID = "HyperLink";
                hyplink.Text = item["Price"].Text;
                hyplink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProductID"], e.Item.ItemIndex);
 
 
 
                GridDataItem item2 = (GridDataItem)e.Item;
                HyperLink hyplink2 = new HyperLink();
                hyplink2.ID = "HyperLink2";
                hyplink2.Text = item2["Price2"].Text;
                hyplink2.Attributes["onclick"] = String.Format("return ShowEditForm2('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProductID"], e.Item.ItemIndex);
 
            }
 
             
        }
    }
}

Code  for Edit Form

<%@ Page Title="" Language="C#"  AutoEventWireup="true" CodeBehind="EditForm.aspx.cs" Inherits="Telerik_Master_Pages.EditForm1" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<head id="Head1" runat="server">
    <title></title>
    <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();
        }
</script>
</head>
<body>
<form id="form1" runat="server">
    <div>
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Vista" DecoratedControls="All" />
<br />
<br />
<asp:DetailsView ID="DetailsView1" DataKeyNames="ProductID" runat="server" AutoGenerateRows="False"
    DataSourceID="SqlDataSource1" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand"
    BorderWidth="0px" CellPadding="0" CellSpacing="7" GridLines="None"
    OnItemUpdating="DetailsView1_ItemUpdating" AllowPaging="True">
    <Fields>
        <asp:BoundField DataField="ProductID" HeaderText="ProductID"
            SortExpression="ProductID" InsertVisible="False" ReadOnly="True" />
        <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
        <asp:BoundField DataField="ProductName" HeaderText="ProductName"
            SortExpression="ProductName" />
        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
        
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
            ShowInsertButton="True" />
    </Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:Rajeev_DBConnectionString %>"
    DeleteCommand="DELETE FROM [Rajeev_product] WHERE [ProductID] = @ProductID"
    InsertCommand="INSERT INTO [Rajeev_product] ([ID], [ProductName], [Price], [Price2]) VALUES (@ID, @ProductName, @Price, @Price2)"
    SelectCommand="SELECT * FROM [Rajeev_product] WHERE ([ProductID] = @ProductID)"
    UpdateCommand="UPDATE [Rajeev_product] SET  [Price] = @Price  WHERE [ProductID] = @ProductID">
    <DeleteParameters>
        <asp:Parameter Name="ProductID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="ID" Type="Int32" />
        <asp:Parameter Name="ProductName" Type="String" />
        <asp:Parameter Name="Price" Type="Decimal" />
        <asp:Parameter Name="Price2" Type="Decimal" />
    </InsertParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="ProductID" QueryStringField="ProductID"
            Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Price" Type="Decimal" />
        <asp:Parameter Name="ProductID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>
 
 </div>
    </form>
</body>
</html>
 Code Behind for Edit Form

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace Telerik_Master_Pages
{
    public partial class EditForm1 : System.Web.UI.Page
    {
         protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
 
            
                DetailsView1.DefaultMode = DetailsViewMode.Edit;
           
            this.Page.Title = "Editing record";
        }
 
        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
            }
           
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
            }
        }
 
        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            //logic to truncate long string to prevent SQL error
            for (int i = 1; i < 4; i++)
            {
                string val = e.NewValues[i - 1].ToString();
                int maxLength = i * 10;
                if (val.Length > maxLength) e.NewValues[i - 1] = val.Substring(0, maxLength);
            }
        }
 
    }
}


The code for EDITFORM2 is almost exactly the same as EDITFORM.aspx
0
Shinu
Top achievements
Rank 2
answered on 24 Dec 2012, 05:22 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridCommandItem)
  {
    GridCommandItem item = (GridCommandItem)e.Item;
    Button btn1 = (Button)item.FindControl("AddNewRecordButton");
    btn1.Visible = false; //for hiding commanditem
    LinkButton lnkbtn1 = (LinkButton)item.FindControl("InitInsertButton");
   lnkbtn1.Visible = false;
  }
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            HyperLink link = new HyperLink();
            link.NavigateUrl = "Page.aspx";//for navigating to new page
            link.CssClass = "class1";//for showing underline in hyperlink
            link.Text = item["Uniquename"].Text;
            item["Uniquename"].Controls.Add(link);
        }
    }

CSS:
.class1
   {
       text-decoration:underline;
   }

Thanks,
Shinu.
0
Rajeev
Top achievements
Rank 1
answered on 26 Dec 2012, 06:23 PM
Thanks it worked. I have another question regarding the  Total (SUM) and Grand Total. If you want me to ask this question in a new thread and Mark this question as Answer. I can do it

If you do Paging(Example 5 records per page and i have 10 records) It will only show the SUM of those 5 records on Page 1 with the Grand Total of Page1. Then it will show the sum of next 5 records on Page 2 with the Grand Total of Page2. Is there a way it will show the SUM of all the records and Grand Total on any Page u go(Page1 Page2) 

If i remove paging then the code works fine. (All the records on one page)

I am doing my code code behind.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
   Decimal total;
        Decimal total2;
        Decimal grantotal;
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                Decimal fieldValue = Convert.ToDecimal(dataItem["Price"].Text);
                Decimal Fieldvalue2 = Convert.ToDecimal(dataItem["Price2"].Text);
  
  
                total += fieldValue;
                total2 += Fieldvalue2;
                // grantotal = fieldValue + Fieldvalue2;
            }
            if (e.Item is GridFooterItem)
            {
                grantotal = Convert.ToDecimal(total) + Convert.ToDecimal(total2);
  
                GridFooterItem footerItem = e.Item as GridFooterItem;
                footerItem["Price"].Text = "total: " + total.ToString();
  
                footerItem["Price2"].Text = "total Price2: " + total2.ToString() + "      " + " Grand Total " + grantotal;
  
  
  
            }
        
  
    
  
              
   
 
}


Thanks
Rajeev
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Dec 2012, 05:38 AM
Hi,

Try the following code to show grant total in all pages

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid1.AllowPaging = false;
    RadGrid1.Rebind();
    foreach (GridDataItem dataItem in RadGrid1.Items)
    {
        Decimal fieldValue = Convert.ToDecimal(dataItem["Price"].Text);
        Decimal Fieldvalue2 = Convert.ToDecimal(dataItem["Price2"].Text);
        total += fieldValue;
        total2 += Fieldvalue2;
        grantotal = fieldValue + Fieldvalue2;
    }
    RadGrid1.AllowPaging = true;
    RadGrid1.Rebind();
    foreach (GridFooterItem footerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Footer))
    {     
        grantotal = Convert.ToDecimal(total) + Convert.ToDecimal(total2);          
        footerItem["Price"].Text = "total: " + total.ToString();
        footerItem["Price2"].Text = "total Price2: " + total2.ToString() + "      " + " Grand Total " + grantotal;          
    }      
}

Thanks,
Shinu.
0
Rajeev
Top achievements
Rank 1
answered on 27 Dec 2012, 09:11 PM
Thanks for all your help.
Rajeev
Tags
Grid
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rajeev
Top achievements
Rank 1
Share this question
or