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

Simple object binding

8 Answers 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 21 Jan 2009, 05:04 PM
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

8 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 21 Jan 2009, 06:20 PM
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.
0
Michael
Top achievements
Rank 1
answered on 01 Feb 2009, 07:42 PM
Many thanks.

MIke
0
Erik
Top achievements
Rank 2
answered on 03 Mar 2009, 04:01 PM
Hi Daniel,

Is there a VB.NET example? I've tried to convert it, but ran into troubles.... It seems to bee my solution..
0
Sebastian
Telerik team
answered on 03 Mar 2009, 04:15 PM
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.
0
Erik
Top achievements
Rank 2
answered on 03 Mar 2009, 05:44 PM
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:

    protected void Page_Init(object sender, EventArgs e) 
    { 
        RadGrid radGrid1 = new RadGrid(); 
        radGrid1.ID = "radGrid1"
        radGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource); 
        radGrid1.AllowMultiRowSelection = true
        radGrid1.AutoGenerateEditColumn = true
        radGrid1.AutoGenerateDeleteColumn = true
        radGrid1.GridLines = GridLines.None; 
        radGrid1.Skin = "Vista"
        radGrid1.AllowMultiRowEdit = true
        radGrid1.DeleteCommand +=new GridCommandEventHandler(RadGrid1_DeleteCommand); 
        radGrid1.InsertCommand += new GridCommandEventHandler(RadGrid1_InsertCommand); 
        radGrid1.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand); 
        radGrid1.ItemCreated +=new GridItemEventHandler(RadGrid1_ItemCreated); 
        radGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; 
 
................ 

which results in vb in:

Protected Sub Page_Init(sender As Object, e As EventArgs) 
        Dim radGrid1 As New RadGrid() 
        radGrid1.ID = "radGrid1" 
        radGrid1.NeedDataSource += New GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource) 
        radGrid1.AllowMultiRowSelection = True 
        radGrid1.AutoGenerateEditColumn = True 
        radGrid1.AutoGenerateDeleteColumn = True 
        radGrid1.GridLines = GridLines.None 
        radGrid1.Skin = "Vista" 
        radGrid1.AllowMultiRowEdit = True 
        radGrid1.DeleteCommand += New GridCommandEventHandler(RadGrid1_DeleteCommand) 
        radGrid1.InsertCommand += New GridCommandEventHandler(RadGrid1_InsertCommand) 
        radGrid1.UpdateCommand += New GridCommandEventHandler(RadGrid1_UpdateCommand) 
        radGrid1.ItemCreated += New GridItemEventHandler(RadGrid1_ItemCreated) 
        radGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top 
 
..... 

i cannot translate it myself, because i do not know C#.. Something with AddressOf i suppose?
0
Princy
Top achievements
Rank 2
answered on 04 Mar 2009, 05:34 AM
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.
0
Hakan
Top achievements
Rank 1
answered on 08 Jul 2013, 02:47 PM
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? 
0
Shinu
Top achievements
Rank 2
answered on 09 Jul 2013, 10:19 AM
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
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Michael
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Sebastian
Telerik team
Princy
Top achievements
Rank 2
Hakan
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or