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

Updating radgrid when item edited in another radgrid

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 2
Keith asked on 29 Jun 2012, 09:27 PM
I have two radgrid controls in a window. Both of the grids initially utilize the same data and both are bound to the underlying data.
In grid1 the last column is a checkbox to which I have attached a click event. What I need to do, because of the way the underlying data will be used, when the checkbox in grid1 is clicked, the corresponding row checkbox in grid2 becomes checked, and I need this to be client-side.

What I have done is use javascript to get the checkbox id, change the reference from grid1 to grid2 and update the related checkbox in grid2 to the checked state of the item in grid1. This works as expected for only the first item in grid1. After some digging, I have found that the checkboxes in grid2 are not numbered in the same fashion as those in grid1, despite having the same columns, data and controls.

For example, the checkbox ID in row0 is grid1_ctl00_ctl04_cbxConfirm. The checkbox in the second grid is grid2_ctl00_ctl04_cbxConfirm. When I look at row1, the source ID is grid1_ctl00_ctl05_cbxConfirm, but the destination is grid2_ctl00_ctl06_cbxConfirm. It seems that checkboxes in grid1 are incremented by 1 for each row, while in grid2, the checkbox ID is being incremented by 2 for each row.

I am not creating any other controls (both grids are identical)

Is there a better way to handle this update?
Is there something I need to look at regarding the control incrementing?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jun 2012, 06:41 AM
Hello,

function CheckOtherChkvox(id,basechk) {
    
               var grid = $find("<%= RadGrid3.ClientID %>");
 
               if (grid) {
                   var MasterTable = grid.get_masterTableView();
                   var Rows = MasterTable.get_dataItems();
                   for (var i = 0; i < Rows.length; i++) {
                       var row = Rows[i];
                       if (row.getDataKeyValue("ID") == id) {
                           var Chk1 = row.findControl("Chk1");
                           $(row.get_element()).find("input[id*='Chk1']").get(0).checked = document.getElementById(basechk).checked;
                       }
 
                   }
               }
<telerik:RadGrid ID
protected void RadGrid2_ItemDataBound1(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            CheckBox Chk1 = item.FindControl("Chk1") as CheckBox;
            Chk1.Attributes.Add("OnClick", "CheckOtherChkvox('" + item.GetDataKeyValue("ID").ToString() + "','" + Chk1.ClientID+ "');");
            //Chk1.Attributes.Add("OnClick", "alert('a');");
        }
    }
 
 
    protected void RadGrid3_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
        RadGrid3.DataSource = data;
 
 
    }
 
 
 protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
        RadGrid2.DataSource = data;
 
 
    }
="RadGrid2" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource"
OnItemDataBound="RadGrid2_ItemDataBound1">
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">
                <Columns>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:CheckBox ID="Chk1" runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
           
        </telerik:RadGrid>
        <telerik:RadGrid ID="RadGrid3" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid3_NeedDataSource">
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">
                <Columns>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:CheckBox ID="Chk1" runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>


Thanks,
Jayesh Goyani
0
Keith
Top achievements
Rank 2
answered on 02 Jul 2012, 01:19 PM
Thanks for a great solution. The only thing left for me now is to work out posting my edits.
Tags
Grid
Asked by
Keith
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Keith
Top achievements
Rank 2
Share this question
or