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

Abbid

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

Hi
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" />
</telerik:RadComboBox>
</ItemTemplate>
<
HeaderStyle Width="30%"></HeaderStyle>
</telerik:GridTemplateColumn>

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

I am accessing the values of Bound Columns like this:

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);
}

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
0
Sebastian
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:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Best regards,
Stephen
the Telerik team

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