Simple object binding

9 posts, 1 answers
  1. Michael
    Michael avatar
    17 posts
    Member since:
    Oct 2008

    Posted 21 Jan 2009 Link to this post

    Hi

    I've a requirement to create an editable grid that will bind to an object. Each row would contain a number of editable checkboxes, and drop down lists. I would nee to create the columns and related settings entierly dynamically.

    Could anyone point me to some resource that would help me get started? Most of the examples I've seem seem to be data bound.

    Thanks.
    Mike

  2. Answer
    Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 21 Jan 2009 Link to this post

    Hello Michael,

    For your convenience I created simple demo illustrating the desired functionality. Please find it attached to this post.

    Hope this helps.

    Kind regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    17 posts
    Member since:
    Oct 2008

    Posted 01 Feb 2009 Link to this post

    Many thanks.

    MIke
  5. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 03 Mar 2009 Link to this post

    Hi Daniel,

    Is there a VB.NET example? I've tried to convert it, but ran into troubles.... It seems to bee my solution..
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 03 Mar 2009 Link to this post

    Hello Proovit,

    You can use our free online converter for this purpose:

    http://converter.telerik.com/

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 03 Mar 2009 Link to this post

    hello Daniel,

    Yes, i know. But some of the code is not translating well. Especially the event handling:

    For i.e. the default.asp.cs has:

    1     protected void Page_Init(object sender, EventArgs e) 
    2     { 
    3         RadGrid radGrid1 = new RadGrid(); 
    4         radGrid1.ID = "radGrid1"
    5         radGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource); 
    6         radGrid1.AllowMultiRowSelection = true
    7         radGrid1.AutoGenerateEditColumn = true
    8         radGrid1.AutoGenerateDeleteColumn = true
    9         radGrid1.GridLines = GridLines.None; 
    10         radGrid1.Skin = "Vista"
    11         radGrid1.AllowMultiRowEdit = true
    12         radGrid1.DeleteCommand +=new GridCommandEventHandler(RadGrid1_DeleteCommand); 
    13         radGrid1.InsertCommand += new GridCommandEventHandler(RadGrid1_InsertCommand); 
    14         radGrid1.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand); 
    15         radGrid1.ItemCreated +=new GridItemEventHandler(RadGrid1_ItemCreated); 
    16         radGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; 
    17  
    18 ................ 

    which results in vb in:

    1 Protected Sub Page_Init(sender As Object, e As EventArgs) 
    2         Dim radGrid1 As New RadGrid() 
    3         radGrid1.ID = "radGrid1" 
    4         radGrid1.NeedDataSource += New GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource) 
    5         radGrid1.AllowMultiRowSelection = True 
    6         radGrid1.AutoGenerateEditColumn = True 
    7         radGrid1.AutoGenerateDeleteColumn = True 
    8         radGrid1.GridLines = GridLines.None 
    9         radGrid1.Skin = "Vista" 
    10         radGrid1.AllowMultiRowEdit = True 
    11         radGrid1.DeleteCommand += New GridCommandEventHandler(RadGrid1_DeleteCommand) 
    12         radGrid1.InsertCommand += New GridCommandEventHandler(RadGrid1_InsertCommand) 
    13         radGrid1.UpdateCommand += New GridCommandEventHandler(RadGrid1_UpdateCommand) 
    14         radGrid1.ItemCreated += New GridItemEventHandler(RadGrid1_ItemCreated) 
    15         radGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top 
    16  
    17 ..... 

    i cannot translate it myself, because i do not know C#.. Something with AddressOf i suppose?
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Mar 2009 Link to this post

    Hello Proovit,

    To add event handlers to your grid you can try out the following code:
    VB:
                Protected Sub Page_Init(sender As Object, e As EventArgs)  
                Dim radGrid1 As New RadGrid()  
                radGrid1.ID = "radGrid1"  
                AddHandler radGrid1.NeedDataSource, AddressOf RadGrid1_NeedDataSource  
                radGrid1.AllowMultiRowSelection = True  
                radGrid1.AutoGenerateEditColumn = True  
                radGrid1.AutoGenerateDeleteColumn = True  
                radGrid1.GridLines = GridLines.None  
                radGrid1.Skin = "Vista"  
                radGrid1.AllowMultiRowEdit = True  
                AddHandler radGrid1.DeleteCommand, AddressOf RadGrid1_DeleteCommand 
                AddHandler radGrid1.InsertCommand, AddressOf RadGrid1_InsertCommand 
                AddHandler radGrid1.UpdateCommand, AddressOf RadGrid1_UpdateCommand 
                AddHandler radGrid1.ItemCreated, AddressOf RadGrid1_ItemCreated       
                radGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top  
                    .....  

    Thanks
    Princy.
  9. Hakan
    Hakan avatar
    12 posts
    Member since:
    May 2013

    Posted 08 Jul 2013 Link to this post

    Hey Daniel,

    Your sample project is really great! Thanks.

    I am trying to bind the dropdowncolumn, and I found your sample difficult for me to understand.

    I have my main table, (to bind) and the second table to bind the dropdownlist. In edit mode, I will bind the dropdowncolumn to m y second table. then I will choose the selectedvalue manually.

    Can you make a simple version of your project for this scenario? 
  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2013 Link to this post

    Hi Hakan,

    Please try the below code snippet.Let me know if any concern.

    ASPX:
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="false"
        AutoGenerateEditColumn="true" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView>
            <CommandItemSettings />
            <Columns>
                <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
                <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" />
                <telerik:GridDropDownColumn HeaderText="Quantity" DropDownControlType="DropDownList"
                    UniqueName="Quantity">
                </telerik:GridDropDownColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    public static string connection = WebConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
       SqlConnection conn = new SqlConnection(connection);
       public SqlCommand SqlCommand = new SqlCommand();
       DataTable table = new DataTable();
          
       protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           string selectQueryDropDown = "SELECT top 10 [Quantity] FROM [Order Details]";
           SqlDataAdapter adapter = new SqlDataAdapter(selectQueryDropDown, conn);
           conn.Open();
           adapter.Fill(table);
           conn.Close();
     
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem item = (GridEditableItem)e.Item;
               DropDownList DropDownList1 = (DropDownList)item["Quantity"].Controls[0];
               DropDownList1.DataSource = table;
               DropDownList1.DataTextField = "Quantity";
               DropDownList1.DataValueField = "Quantity";
               DropDownList1.DataBind();
           }
       }
       protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           string selectQueryRadgrid = "SELECT top 10 * FROM [Orders]";
           SqlDataAdapter adapter1 = new SqlDataAdapter(selectQueryRadgrid, conn);
           conn.Open();
           DataTable DropDownTable = new DataTable();
           adapter1.Fill(DropDownTable);
           conn.Close();
           RadGrid1.DataSource = DropDownTable;
            
       }

    Thanks,
    Shinu
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017