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

RadGrid and GridTableView

4 Answers 835 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Winston Yong
Top achievements
Rank 1
Winston Yong asked on 08 Jul 2010, 09:37 AM
Hi!

 I want to access the controls such as dropdown and textbox defined in editformsettings of GridTableView in code behind to populate the values from database when the user clicks on add new record on the GridTable View.. right now i cant access those controls ... like we do in this code
 if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
            {
                GridEditFormItem edititem = (GridEditFormItem)e.Item;
                DropDown txt = (DropDownedititem.FindControl("Dro");//access the DropDown in FormTemplate
            } 
but i want to do when user clicks on add new record, so i extract value from RadGridDataKeyValue and select value from database and populate the controls inside GridTableView ...
note : i want to bind drop down in code behind not in html file..
<telerik:RadGrid ID="RadGridRunDate"  AutoGenerateColumns="false" OnNeedDataSource="RadGridRunDate_NeedDataSource" ShowGroupPanel="true" OnItemCreated="RadGridRunDate_ItemCreated"  OnInsertCommand="RadGridRunDate_InsertCommand" OnDetailTableDataBind="RadGridRunData_DetailTableDataBind" OnItemCommand="RadGridRunDate_ItemCommand"
AllowFilteringByColumn="true" EnableEmbeddedSkins="false" Skin="GridDefault"
AllowPaging="true" AllowSorting="true" runat="server" >
<MasterTableView DataKeyNames="RunDate" EnableHeaderContextMenu="true" EditMode="PopUp" >
 <DetailTables>
<telerik:GridTableView DataKeyNames="RunID" Width="100%"  runat="server" EditMode="PopUp" CommandItemDisplay="Top" Name="Runs">
<Columns>
<telerik:GridBoundColumn SortExpression="RunCode" HeaderText="<%$ Resources:Lang, Run_ID%>"DataField="RunCode" UniqueName="RunCode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="RunDate" HeaderText="<%$ Resources:Lang, Run_Date%>"
DataField="RunDate" UniqueName="RunDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="RunType.RunTypeCode" HeaderText="<%$ Resources:Lang, Run_Type%>"
DataField="RunType.RunTypeCode" UniqueName="RunType.RunTypeCode">
</telerik:GridBoundColumn>                                                   
<telerik:GridBoundColumn SortExpression="TimeWindow.StartTime" HeaderText="<%$ Resources:Lang, Start_Time%>"
DataField="TimeWindow.StartTime" UniqueName="TimeWindow.StartTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="TimeWindow.EndTime" HeaderText="<%$ Resources:Lang, End_Time%>"
DataField="TimeWindow.EndTime" UniqueName="TimeWindow.EndTime">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings InsertCaption="Add New Run" CaptionFormatString="Edit RunID: {0}"
CaptionDataField="RunID" EditFormType="Template">
<FormTemplate>
<table>
<tr>RunCode
<td>
</td>
<td><asp:TextBox runat="server" ID="TextBoxRunCode"></asp:TextBox>
</td>
</tr>
<tr>
<td>RunDate
</td>
<td>
<telerik:RadDatePicker ID="RadDatePickerRunDate" runat="server">
</telerik:RadDatePicker>
</td>
</tr>
<tr>
<td>Depot
</td>
<td>
<asp:Label runat="server" ID="LabelDepotCode"></asp:Label>
</td>
</tr>
<tr>
<td>Run Type
</td>
<td>
</td>
</tr>
<tr>
<td>Start Time
</td>
<td>
<telerik:RadTimePicker ID="RadTimePickerStartTime" runat="server">
</telerik:RadTimePicker>
</td>
</tr>
<tr>
<td>End Time
</td>
<td><telerik:RadTimePicker ID="RadTimePickerEndTime" runat="server">
</telerik:RadTimePicker>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button runat="server" ID="buttonAddRun" Text="Text" /></td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
        </telerik:GridTableView>
    </DetailTables>
        <Columns><telerik:GridBoundColumn HeaderText="<%$ Resources:Lang, Run_Date%>" DataField="RunDate" ItemStyle-CssClass="itemStyle" FilterControlWidth="30px"></telerik:GridBoundColumn>
        </Columns>             <CommandItemTemplate>
</CommandItemTemplate>
    </MasterTableView>
     <ClientSettings>
        <Selecting AllowRowSelect="true" />
     </ClientSettings>               
</telerik:RadGrid>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jul 2010, 11:43 AM
Hello Winston,

You can differentiate between the grid rows in hierarchy by using GridTableView Name property. Here is the code sample.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted && e.Item.OwnerTableView.Name == "Runs")
      {
          GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
          TextBox txt = (TextBox)insertItem.FindControl("TextBoxRunCode");
      }
  }

Also the documentation shows different ways to distinguish grid rows in hierarchy on ItemCreated/ItemDataBound .

Check out the documentation to know more about distinguishing edit/insert modes on ItemCreated/ItemDataBound:
http://www.telerik.com/help/aspnet-ajax/grddistinguisheditinsertmodeonitemcreateditemdatabound.html

Thanks,
Princy.
0
Winston Yong
Top achievements
Rank 1
answered on 09 Jul 2010, 01:47 AM
HI Thanks for reply and it helped me also..

I have one more question... that i want to edit only the detail tables values, not the radgrid value..
my scenario is the user can expand radgrid(parent) and add, edit and delete details tables(Chile) value only..

i am defining client dbRowClick in clientsetting but it is firing for Radgrid not for Detail table...

Kind Regards
Winston
0
Winston Yong
Top achievements
Rank 1
answered on 09 Jul 2010, 05:38 AM
Hi!

I have figured it out Thanks for your help.

kind Regards
winston
0
Lukus
Top achievements
Rank 1
answered on 20 Oct 2011, 09:26 PM
Winston,

I am currently having the same issue.  I cannot get my "oncommand" event to fire from my detail table.  Please let me know what you did to fix your issue.

Thanks
Tags
Grid
Asked by
Winston Yong
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Winston Yong
Top achievements
Rank 1
Lukus
Top achievements
Rank 1
Share this question
or