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

GridTemplateColumn & LinkButton

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
New User
Top achievements
Rank 1
New User asked on 21 Jul 2011, 06:28 PM
I'm trying to have a linkbutton in my grid and databind the text to a field in my dataset and it doesn't seem to be working.  Here are my code snippets

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="OpenItemsInventory.aspx.cs"

 

 

Inherits="Sterling.SNEF.Tax.Web.OpenItemsInventory" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml">

 

<

 

head runat="server">

 

 

<title>Open Items Inventory</title>

 

</

 

head>

 

<

 

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

 

<

 

script type="text/javascript">

 

 

var rad_val;

 

 

 

function onFutureInventory(sender, args) {

 

document.getElementById(

'<%= btnFutureInventory.ClientID %>').disabled = true;

 

 

GetRadioValue();

 

var windowURL = "FutureInventoryDialog.aspx?ViewByType=" + rad_val

 

 

var oWnd = $find("<%= dlgFutureInventory.ClientID%>");

 

oWnd.setUrl(windowURL);

oWnd.SetSize(500, 500);

oWnd.show();

oWnd.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.Close);

oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close);

oWnd.SetModal(

true);

 

 

}

 

 

function GetRadioValue()

 

{

message =

"";

 

surplusMessage =

"";

 

 

 

if (document.getElementById('<%= rdoAssignee.ClientID %>').checked)

 

{

rad_val =

"Assignee";

 

}

 

else

 

{

rad_val =

"State";

 

}

}

 

 

function onFutureInventoryClose(sender, eventArgs) {

 

document.getElementById(

'<%= btnFutureInventory.ClientID %>').disabled = false;

 

}

 

</

 

script>

 

</

 

telerik:RadCodeBlock>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<telerik:RadScriptManager ID="OpenItemsInventoryScriptManager" runat="server">

 

 

</telerik:RadScriptManager>

 

 

<telerik:RadWindow ID="dlgFutureInventory" runat="server" Skin="Web20" EnableViewState="False"

 

 

KeepInScreenBounds="True" ReloadOnShow="True" ShowContentDuringLoad="False" VisibleStatusbar="False"

 

 

Behaviors="None" OnClientClose="onFutureInventoryClose" onclientOverlay="True">

 

 

</telerik:RadWindow>

 

 

<asp:Label ID="lblViewBy" runat="server" Font-Bold="True" Text="View By:"></asp:Label>

 

 

<asp:RadioButton ID="rdoAssignee" runat="server" Text="Assignee" GroupName="ViewByGroup"

 

 

OnCheckedChanged="ViewByGroup_CheckedChanged" Checked="true" AutoPostBack="true" />&nbsp;&nbsp;

 

 

<asp:RadioButton ID="rdoState" runat="server" Text="State" GroupName="ViewByGroup"

 

 

OnCheckedChanged="ViewByGroup_CheckedChanged" AutoPostBack="true" />

 

 

<br />

 

 

<br />

 

 

<table border="1">

 

 

<tr>

 

 

<td rowspan="2" align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrAssignee" runat="server" Text="Assignee" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td rowspan="2" align="center" style="width: 100px;">

 

 

<asp:Label ID="Label2" runat="server" Text="Jurisdictions" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td colspan="2" align="center" style="width: 200px;">

 

 

<asp:Label ID="Label3" runat="server" Text="Open Items by Age" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td rowspan="2" align="center" style="width: 100px;">

 

 

<asp:Label ID="Label4" runat="server" Text="Items Left to Pay" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td rowspan="2" align="center" style="width: 100px;">

 

 

<asp:Label ID="Label5" runat="server" Text="%Complete" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="Label6" runat="server" Text="Prior" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="Label7" runat="server" Text="Current" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="Label1" runat="server" Text="Totals" Font-Bold="True"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrJurisdictions" runat="server"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrPrior" runat="server"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrCurrent" runat="server"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrItemsLeft" runat="server"></asp:Label>

 

 

</td>

 

 

<td align="center" style="width: 100px;">

 

 

<asp:Label ID="lblhdrPctComplete" runat="server"></asp:Label>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

<br />

 

 

<table>

 

 

<tr>

 

 

<td>

 

 

<asp:Label ID="lblCurrentandPrior" runat="server" Font-Bold="True" Font-Size="Large">Current and

 

Prior Inventory by Assignee

</asp:Label>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td>

 

 

<telerik:RadGrid ID="grdCurrentandPrior" runat="server" AllowSorting="True" AutoGenerateColumns="False"

 

 

GridLines="None" Skin="Outlook" Style="margin-right: 0px" Width="673px" Height="260px" >

 

 

<ExportSettings FileName="OpenItemsCurrentInventory" IgnorePaging="True" OpenInNewWindow="True">

 

 

<Excel Format="ExcelML" />

 

 

</ExportSettings>

 

 

<MasterTableView>

 

 

<Columns>

 

 

<telerik:GridTemplateColumn HeaderText="Assignee" UniqueName="clmAssigneeState">

 

 

<HeaderStyle Font-Bold="True" Width="100px" HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:LinkButton ID="dataInfo" runat="server" Text='<%# Eval("Assignee") %>' />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Jurisdictions" UniqueName="clmJurisdictions">

 

 

<HeaderStyle Font-Bold="True" Width="100px" HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:LinkButton ID="jurisdiction" runat="server" Text='<%# Eval("JurisdictionCount") %>' />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn UniqueName="TemplateColumn">

 

 

<HeaderTemplate>

 

 

<table id="Table1" cellspacing="1" cellpadding="1" width="200px" border="1">

 

 

<tr>

 

 

<td colspan="2" align="center">

 

 

<b>Open Items by Age</b>

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td align="center" width="50%">

 

 

<b>Prior</b>

 

 

</td>

 

 

<td align="center" width="50%">

 

 

<b>Current</b>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<table id="Table2" cellspacing="1" cellpadding="1" width="260px" border="1">

 

 

<tr>

 

 

<td width="50%">

 

 

<asp:LinkButton ID="LftToPay" runat="server" Text='<%# Eval("OpenItemsCountPrior") %>' />

 

 

</td>

 

 

<td width="50%">

 

 

<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("OpenItemsCountELD") %>' />

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn HeaderText="Items Left to Pay" UniqueName="clmItemsLefttoPay">

 

 

<HeaderStyle Font-Bold="True" Width="100px" HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<asp:LinkButton ID="LftToPay" runat="server" Text='<%# Eval("TotalRemainingItems") %>' />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn HeaderText="% Complete" UniqueName="clmPctComplete" DataField="PercentComplete">

 

 

<HeaderStyle Font-Bold="True" Width="100px" HorizontalAlign="Center" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="AssigneeEmployeeKey" ReadOnly="True"

 

 

UniqueName="AssigneeEmployeeKey" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

<HeaderStyle BorderStyle="Solid" />

 

 

<ClientSettings>

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

<br />

 

 

<table>

 

 

<tr>

 

 

<td>

 

 

<asp:Button ID="btnFutureInventory" runat="server" Text="Future Inventory" SkinID="Web20" OnClientClick="onFutureInventory(); return false;"

 

 

Width="164px" UseSubmitBehavior="false" />

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</form>

 

</

 

body>

 

</

 

html>

 



and here is the datatable I'm trying to bind to.

DataTable

 

myDataTable = new DataTable();

 

 

DataColumn myDataColumn;

 

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.String");

 

myDataColumn.ColumnName =

"Assignee";

 

myDataColumn.DefaultValue =

"Dixon, Kristi";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"JurisdictionCount";

 

myDataColumn.DefaultValue =

"15";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"OpenItemsCountPrior";

 

myDataColumn.DefaultValue =

"2";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"OpenItemsCountELD";

 

myDataColumn.DefaultValue =

"153";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"TotalRemainingItems";

 

myDataColumn.DefaultValue =

"155";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Decimal");

 

myDataColumn.ColumnName =

"PercentComplete";

 

myDataColumn.DefaultValue =

"0.00";

 

myDataTable.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"AssigneeEmployeeKey";

 

myDataColumn.DefaultValue =

"1113";

 

myDataTable.Columns.Add(myDataColumn);

 

grdCurrentandPrior.DataSource = myDataTable.DefaultView;

grdCurrentandPrior.DataBind();




and another question when this is done will it allow me to sort the column by the text on the link button?

Thanks
Kristi

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 22 Jul 2011, 11:48 AM
Hello,
In order to set the default value for columns, you should create new rows. It sets the default value for the column when you are creating new rows.

C#:
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
. . . .
myDataTable.Rows.Add(row);
grdCurrentandPrior.DataSource = myDataTable;
grdCurrentandPrior.DataBind();

Note:After inspecting your code, I found that the two LinkButtons are having similar IDs.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">
 <ItemTemplate>
        <asp:LinkButton ID="LftToPay" runat="server" Text='<%# Eval("OpenItemsCountPrior") %>' />
       <asp:LinkButton ID="LftToPay1" runat="server" Text='<%# Eval("TotalRemainingItems") %>' />
 </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy.
Tags
Grid
Asked by
New User
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or