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

Binding RadGridView GridTemplateColumn to Custom List

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 15 May 2012, 03:09 PM
hi guys,

I am trying to bind a list of a custom class to the following RadGridView:

<rad:RadGrid Skin="Office2007" runat="server"
                          
                                       
                               
                                          OnItemDataBound="gridAdd_ItemDataBound"
                         AllowAutomaticDeletes="True"
                         OnItemCommand="RadGrid1_ItemCommand"
                        
                         AllowAutomaticInserts="True"
                         OnInsertCommand="gridAdd_InsertCommand"
                       NoMasterRecordsText="No Files selected for this PO"
                       OnDeleteCommand="gridAdd_ItemDeleted"
                        AutoGenerateColumns="false"  id="gridAdd"
                            AllowPaging="true" PageSize="5" onneeddatasource="gridAdd_NeedDataSource">
                       <MasterTableView   NoMasterRecordsText="No Files selected for this PO"  EditMode="InPlace" AllowAutomaticUpdates="false"   AllowAutomaticInserts="true" CommandItemDisplay="Bottom"   DataKeyNames="ID,FileID, GVMXID"  >
                            <Columns>
                                      
                            <rad:GridEditCommandColumn  ButtonType="LinkButton" UniqueName="EditCommandColumn2">
                                <HeaderStyle Width="20px" />
                                 
                            </rad:GridEditCommandColumn>   
                                 
                              
 
                                <rad:GridTemplateColumn HeaderText="File" >
                                <ItemTemplate>
           
                                    <rad:RadComboBox Visible="false"    CheckBoxes="true"   OnDataBinding="comboFiles_DataBind" DataSourceID="odsFiles"     Height="200" Skin="Vista" ID="comboFiles" Width="200"   DataTextField="OriginalName" DataValueField="ID"    runat="server">
                                   
                                    </rad:RadComboBox>
                                    <asp:Label ID="lblFileName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FileName") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle  Wrap="true" Width="100"  HorizontalAlign="Center" />
                                 <HeaderStyle ForeColor="#4e6ea4" HorizontalAlign="Center" Font-Bold="true" />
                               </rad:GridTemplateColumn>
                               
                               
                              <rad:GridTemplateColumn HeaderText="TM" >
                                <ItemTemplate>
           
                                    <rad:RadComboBox Visible="false" AppendDataBoundItems="true"   Height="200" Skin="Vista" ID="comboTMs" DataSourceID="odsTMs"  DataTextField="TMName" DataValueField="ID" runat="server">
                                    
                                    </rad:RadComboBox>
                                    <asp:Label ID="lblTMName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.TMName") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle  Wrap="true" Width="100"  HorizontalAlign="left" />
                                 <HeaderStyle ForeColor="#4e6ea4" HorizontalAlign="Center" Font-Bold="true" />
                               </rad:GridTemplateColumn>
 
                               <rad:GridTemplateColumn HeaderText="Tag Settings" >
                                <ItemTemplate>
          <table>
          <tr><td style="border:0px; min-width:150px;">
             <asp:CheckBox Visible="false" onclick="toggle(this)"  runat="server" Checked="true" ID="chkDefault" Text="Use Default Tag Settings" />
          </td></tr>
           
          <tr><td style="border:0px;">
           <asp:FileUpload Visible="false"  runat="server" ClientIDMode="Static" ID="fileUpload" />
          </td></tr>
          </table>
                                   
                                 
                                    <asp:Label ID="lblTagSettings" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.TagSettings") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle  Wrap="true" Width="100"  HorizontalAlign="Center" />
                                 <HeaderStyle ForeColor="#4e6ea4" HorizontalAlign="Center" Font-Bold="true" />
                               </rad:GridTemplateColumn>
 
                                 
 
                                <rad:GridButtonColumn ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this file from PO?" ButtonType="ImageButton"
                                CommandName="Delete" Text="Delete" UniqueName="DeleteDiscount">
                                <HeaderStyle Width="20px" />
                          
                            </rad:GridButtonColumn>
                            </Columns>
                            <CommandItemSettings ShowRefreshButton="false"  AddNewRecordText="Add New Files" />
                        </MasterTableView>
                         
                    </rad:RadGrid>

Code behind, NeedDataSource Event:

protected void gridAdd_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
     
    gridAdd.DataSource = (List<POFilesInMemory>)Session["POFiles"];
 
  
}

The Grid is showing empty. I checked the List<POFilesInMemory> and it has items:

Here is the class :
public class POFilesInMemory
{
    public int FileID { get; set; }
    public string FileName { get; set; }
    public int TMID { get; set; }
    public string TMName { get; set; }
 
    public string TagSettingsName { get; set; }
}


Any ideas guys ?


2 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 16 May 2012, 04:28 AM
I have tried to use the DataItem.Container and cast it to the custom class but got a telerik error.
0
Eyup
Telerik team
answered on 18 May 2012, 09:50 AM
Hello Joseph,

I have created a simple RadGrid page using the provided code. Please find the attached project and let me know if I am missing something out. Try to replace my custom datasource with your own and to determine the crucial differences between our applications. 

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Joseph
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or