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

Get value of GridBoundColumn in GridTableView

5 Answers 1009 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bharat kumar
Top achievements
Rank 1
bharat kumar asked on 02 Aug 2010, 04:58 PM
Hi,
i have aone terelik grid having Gridtable view and i want to fetch the value of Grid bound column and on basic of that want to set the navigate URL of Gridhyperlinkcolumn.

please help.

below is the code of grid..how to get the value of column and set navigate url in code behind .
please help.

<

 

telerik:RadGrid runat="server"

 

 

ID="grdActions"

 

 

AllowPaging="false"

 

 

Width="750px"

 

 

AutoGenerateColumns="false"

 

 

Skin="Office2007"

 

 

DataSourceID="TaskActionsDataSource"

 

 

OnPreRender="grdActions_PreRender"

 

 

OnItemCommand="grdActions_ItemCommand"

 

 

OnRowDrop="grdActions_RowDrop"

 

 

OnItemDataBound="grdActions_ItemDataBound"

 

 

 

 

>

 

 

 

<ClientSettings EnableAlternatingItems="true"

 

 

EnableRowHoverStyle="true"

 

 

AllowExpandCollapse="false"

 

 

AllowRowsDragDrop="true"

 

 

>

 

 

<Selecting AllowRowSelect="True" />

 

 

</ClientSettings>

 

 

 

<MasterTableView DataKeyNames="Id" TableLayout="Fixed"

 

 

AllowMultiColumnSorting="false"

 

 

AllowFilteringByColumn="false"

 

 

AlternatingItemStyle-BackColor="#F2F3F5"

 

 

>

 

 

 

<DetailTables>

 

 

 

<telerik:GridTableView HeaderStyle-BackColor="Beige" CommandItemStyle-BackColor="Beige"

 

 

Name="DetailsTable"

 

 

DataSourceID="ActionModuleCollectionDataSource"

 

 

DataKeyNames="Id"

 

 

AutoGenerateColumns="false"

 

 

CommandItemDisplay="Top"

 

 

TableLayout="Fixed"

 

 

HeaderStyle-CssClass="hideGridHeader"

 

 

NoDetailRecordsText="There is no training, meeting or procurement attached to the action above"

 

 

CssClass="detailGridMargin"

 

 

 

>

 

 

<CommandItemTemplate>

 

 

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

 

 

<asp:LinkButton ID="btnAddTraining" runat="server" CommandName="AddTraining" Font-Names="Tahoma" Font-Size="11px"><img style="border:0px; width: 25px; height: 17px; vertical-align:middle;" alt="" src="../Images/add_training.png" />Add Training</asp:LinkButton>&nbsp;&nbsp;

 

 

<asp:LinkButton ID="btnAddMeeting" runat="server" CommandName="AddMeeting" Font-Names="Tahoma" Font-Size="11px"><img style="border:0px; width: 25px; height: 17px; vertical-align:middle;" alt="" src="../Images/add_meeting.png" />Add Meeting</asp:LinkButton>&nbsp;&nbsp;

 

 

<asp:LinkButton ID="btnAddProcurement" runat="server" CommandName="AddProcurement" Font-Names="Tahoma" Font-Size="11px"><img style="border:0px; width: 25px; height: 17px; vertical-align:middle;" alt="" src="../Images/add_procurement.png" />Add Procurement</asp:LinkButton>&nbsp;&nbsp;

 

 

</div>

 

 

</CommandItemTemplate>

 

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="Id" MasterKeyField="Id" />

 

 

</ParentTableRelation>

 

 

 

<Columns>

 

 

 

<telerik:GridBoundColumn UniqueName="ModuleType" DataField="ModuleType" HeaderStyle-Width="100px"></telerik:GridBoundColumn>

 

 

 

 

 

<telerik:GridHyperLinkColumn UniqueName="meetingurl"

 

 

DataTextField="Title" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="../Meeting/Meeting.aspx?actionId={0}&ViewMode=ReadOnly"

 

 

>

 

 

</telerik:GridHyperLinkColumn>

 

 

</Columns>

 

 

 

</telerik:GridTableView>

 

 

 

</DetailTables>

 

 

 

<Columns>

 

 

<telerik:GridBoundColumn

 

 

DataField="SortCode"

 

 

Visible="true"

 

 

HeaderText="#"

 

 

HeaderStyle-Width = "30"

 

 

ItemStyle-Font-Bold="true"

 

 

ItemStyle-Font-Names="Tahoma"

 

 

>

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridTemplateColumn UniqueName="TemplateColumn" InitializeTemplatesFirst="false">

 

 

<HeaderTemplate>

 

 

<table id="Table1" cellspacing="0" cellpadding="0" border="0">

 

 

<tr>

 

 

<td colspan="0">

 

 

<b>Action Details</b>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

 

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

 

 

 

<tr>

 

 

<td style="border-width: 0px;"><input type="hidden" id="hiddenActionId" value="<%# Eval("Id") %>" /></td>

 

 

</tr>

 

 

 

<tr>

 

 

<td colspan="6" style="width: 200px; font-size: 12px; font-family: Tahoma;">

 

 

<b>Name:&nbsp;</b><%# Eval("Description") %> (<%# Eval("TypeName") %>) <%# Convert.ToBoolean(Eval("Location").Equals("")) ? "" : ":: " + Eval("Location")%>

 

 

</td>

 

 

<td align="right">

 

 

<img src="../images/status_<%# Eval("StatusName")%>.png" alt="<%# Eval("StatusName")%>" />

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td colspan="4" style="width: 250px; font-size: 12px; font-family: Tahoma;">

 

 

<b>Output:&nbsp;</b> <%# Eval("Output") %>

 

 

</td>

 

 

<td rowspan="3" style="width: 50px; font-size: 12px; font-family: Tahoma;" align="center">

 

 

<img src="../images/status_<%# Convert.ToBoolean(Eval("NoBudgetFlag")) ? "nobudget" : "budget" %>.png"

 

 

alt='<%# Convert.ToBoolean(Eval("NoBudgetFlag")) ? "No budget required for this action" : "Budget estimation required for this action" %>' />

 

 

</td>

 

 

 

<td colspan="2" rowspan="3" style="width: auto; font-size: 12px; font-family: Tahoma;" align="center">

 

$ <%

# Eval("TotalEstimationInDollar") %> &nbsp;&nbsp;&nbsp;&nbsp; <%# Eval("TotalEstimationInEuro") %>

 

 

 

<br />

 

<%

if (iViewBudget == 0)

 

{ %>

 

<a href="#" onclick="openRadWindowEstimation('<%# DataBinder.Eval(Container.DataItem, "Id") %>'); return false;" id="linkEstimation" class="smallFont" style="font-size: 9px; font-weight:bold; font-family: Tahoma; color: #0099FF;">[VIEW/MODIFY BUDGET]</a><% } %>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td colspan="4" style="font-size: 12px; font-family: Tahoma;">

 

 

<b>Date:&nbsp;</b> <%# Eval("StartDate") %> <%# Convert.ToBoolean(Eval("CompletionDate").Equals("")) ? "" : " to " + Eval("CompletionDate") %>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td colspan="4" style="font-size: 12px; font-family: Tahoma;">

 

 

<b>Comment:&nbsp;</b> <%# Eval("Comment") %>

 

 

</td>

 

 

</tr>

 

 

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

 

 

<script language="javascript" type="text/javascript">

 

 

function RefreshFinancialRelatedGrids(RadWindow) {

 

$find(

'<%=this.RadAjaxManager1.ClientID%>').ajaxRequest("Rebind");

 

}

 

function openRadWindowEstimation(actionId) {

 

 

 

// var lnkProbisWindow = document.getElementById("ctl00_messagePanelsContent_contentPlaceHolder_fvTaskDetail_linkEstimation");

 

 

// var hdnViewmodifyBudget = document.getElementById("ctl00_messagePanelsContent_contentPlaceHolder_fvTaskDetail_hdnViewmodifyBudget");

 

 

//

 

 

// if (hdnViewmodifyBudget.value == "1")

 

 

// lnkProbisWindow.enabled = false;

 

 

// else {

 

 

var oWnd = radopen("Task_Estimation.aspx?actionid=" + actionId + "&disableMaster=1", "RadWindowTaskEstimation");

 

oWnd.Center();

 

//}

 

}

 

 

</script>

 

 

</telerik:RadCodeBlock>

 

 

<telerik:RadWindowManager ID="RadWindowManagerTaskEstimation" runat="server" Modal="true">

 

 

<Windows>

 

 

<telerik:RadWindow ID="RadWindowTaskEstimation" runat="server"

 

 

DestroyOnClose="true" Modal="true"

 

 

Skin="Vista" Animation="None" ShowContentDuringLoad="false" VisibleStatusbar="false"

 

 

KeepInScreenBounds="true" Width="1000px" Height="750px" Behavior="Close" />

 

 

</Windows>

 

 

</telerik:RadWindowManager>

 

 

</table>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2010, 06:03 AM
Hello Bharat,

You can try the following code snippet in ItemDataBound event to set the url of HyperLinkColumn from code behind.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
  if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetailsTable")
   {
     GridDataItem item = (GridDataItem)e.Item;
     string id = item.GetDataKeyValue("Id").ToString(); // access the DataKeyName 'Id'
     HyperLink link = (HyperLink)item["meetingurl"].Controls[0];
     link.NavigateUrl = "../Meeting/Meeting.aspx?actionId="+id+"&ViewMode=ReadOnly"; //setting url
   }
 }

Thanks,
Princy.
0
bharat kumar
Top achievements
Rank 1
answered on 03 Aug 2010, 09:00 AM

Thanks for your reply.
but i cant access the value of GridBoundColumn UniqueName="ModuleType" which is required to set the navigate url property.

<

 

telerik:GridBoundColumn UniqueName="ModuleType" DataField="ModuleType" HeaderStyle-Width="100px"></telerik:GridBoundColumn>

 


how to fetch the value of above field in code behind as you done for hyperlink.

please advice.
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2010, 07:12 AM
Hello Bharat,

 Using the UniqueName property of a column access the GridBoundColumn, and then use the Text property to get the cell's value.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
  if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetailsTable")
   {
     GridDataItem item = (GridDataItem)e.Item;
     string moduleType = item["ModuleType"].Text;//access the column value with UniqueName
     . . . . . . . . . . .  . . . . .
   }
 }

Please take a look at the following documentation which explains how to access cells and rows in a grid.
Accessing cells and rows

Thanks,
Princy.
0
Brew Hutch
Top achievements
Rank 1
answered on 01 Aug 2011, 02:31 PM
Hello Princy,
The link to "Accessing cells and rows" is dead. Can you get it working? I have to learn this stuff.
Thanks,
Brew
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Aug 2011, 06:58 PM
hi,

accessing cells and rows

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
bharat kumar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
bharat kumar
Top achievements
Rank 1
Brew Hutch
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or