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


1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
AMS asked on 02 Oct 2008, 09:49 AM

I am facing a problem in telerik grid.

I have used BoundColumns as well as Template Columns like RadComboBox and MaskedTextBox in my Grid.


telerik:GridBoundColumn DataField="TimesheetDate" HeaderText="Timesheet Date" UniqueName="TimesheetDate" HeaderStyle-Width="20%">
<HeaderStyle Width="20%"></HeaderStyle></telerik:GridBoundColumn>

<telerik:GridTemplateColumn HeaderText="Location" HeaderStyle-Width="30%" UniqueName="Location"><ItemTemplate>
<telerik:RadComboBox ID="RadComboBox6" Runat="server" CssClass="bodytxt" DataTextField="desc" DataValueField="Id" MarkFirstMatch="True" Skin="Web20" ToolTip="Select a recipient" Width="200px" DataSourceID="sqlLocations" Font-Size="10pt">
<CollapseAnimation Duration="200" Type="OutQuint" />
HeaderStyle Width="30%"></HeaderStyle>

<telerik:GridTemplateColumn HeaderText="Time In" HeaderStyle-Width="15%" UniqueName="TimeIn"> 
<asp:TextBox ID="txtTimeIn" runat="server" Width="75px" CssClass="textfields"></asp:TextBox> </ItemTemplate>
HeaderStyle Width="15%"></HeaderStyle>

I am accessing the values of Bound Columns like this:

(GridDataItem item in RadGrid1.MasterTableView.GetItems(new GridItemType[] {GridItemType.Item, GridItemType.AlternatingItem }))
    GridDataItem dataitem = (GridDataItem)item;
    TableCell cell = dataitem["TimesheetDate"];
    TextBox tBox = (TextBox)cell.FindControl("TimesheetDate");
    DateTime timesheetDate = Convert.ToDateTime(dataitem["TimesheetDate"].Text);

The Problem is:
When i try to access the value in the Template column while using the same method, I am getting a 'null' in the Text property.

Please note that i am accessing the values in <ItemTemplate> not in "<EditItemTemplate>"

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 02 Oct 2008, 10:15 AM
Hi Abbid,

For the template column you need to access the textbox/combobox inside it by its id and retrieve its Text/SelectedItem.Text value instead, i.e.:

foreach (GridDataItem item in RadGrid1.MasterTableView.GetItems(new GridItemType[] {GridItemType.Item, GridItemType.AlternatingItem }))  
    GridDataItem dataitem = (GridDataItem)item;  
    TableCell cell = dataitem["TimesheetDate"];  
    TextBox tBox = (TextBox)cell.FindControl("TimesheetDate");  
    DateTime timesheetDate = Convert.ToDateTime(dataitem["TimesheetDate"].Text);  
    string comboSelection = (item.FindControl("RadComboBox6"as RadComboBox).SelectedItem.Text;  
    string txtBoxValue = (item.FindControl("txtTimeIn"as TextBox).Text;  

Further information about how to access cells and rows in RadGrid you can gather from these sources:

Best regards,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question