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

[Solved] Update row from CheckBox in DetailTables

9 Answers 300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 20 Jul 2009, 06:11 AM
Hi

I have a DetailTable where I have a CheckBox and also a RadNumericTextBox, when the CheckBox is clicked, and when the RadNumericTextBox is edited, I want to change the last Total column. I can not see how to reference and FindControl those controls.

                        <DetailTables> 
                            <telerik:GridTableView width="100%" DataKeyNames="ItemId,CampaignId,StockOptionId" Name="Stock" GridLines="None" skinid="Default"
                                <Columns> 
                                    <telerik:gridtemplatecolumn headertext="Select" UniqueName="Select"
                                        <ItemTemplate> 
                                            <asp:CheckBox id="CheckBox1" runat="server" OnCheckedChanged="Add_CheckBox1_CheckChanged" autopostback="true" /> 
                                        </ItemTemplate> 
                                    </telerik:gridtemplatecolumn> 
                                    <telerik:gridtemplatecolumn headertext="Campaign"
                                        <ItemTemplate> 
                                            <asp:Label ID="Add_lblCampaign" runat="server" Text='<%# Eval("Campaign") %>' /> 
                                        </ItemTemplate> 
                                    </telerik:gridtemplatecolumn> 
                                    <telerik:GridTemplateColumn HeaderText="Avail"
                                        <ItemTemplate> 
                                            <asp:Label ID="Add_lblAvail" runat="server" Text='<%# String.Format("{0:n}", Eval("Avail")).Replace(".00", "") %>' /> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Units Text"
                                        <ItemTemplate> 
                                            <asp:Label ID="lblUnitsTextLabel" runat="server" Text='<%# Eval("UnitsText") %>' /> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Units Qty"
                                        <ItemStyle Width="90px" /> 
                                        <ItemTemplate> 
                                            <telerik:RadNumericTextBox ID="Add_tbUnitsQty" Enabled="false" AutoPostBack="true" OnTextChanged="Add_tbUnitsQty_TextChanged"  
                                                ShowSpinButtons="True" Width="80px" Type="Number" runat="server" Culture="en-AU" InvalidStyleDuration="100" MinValue="1"
                                                <NumberFormat DecimalDigits="0" /> 
                                            </telerik:RadNumericTextBox> 
                                          <asp:RequiredFieldValidator ID="Add_rfvUnitsQty" runat="server" Enabled="false" ControlToValidate="Add_tbUnitsQty" ErrorMessage="Required" Display="Dynamic" /> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                    <telerik:GridTemplateColumn HeaderText="Total"
                                        <ItemTemplate> 
                                            <asp:label id="Add_lblTotal" runat="server" /> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                </Columns> 
                            </telerik:GridTableView> 
                        </DetailTables> 

        protected void Add_CheckBox1_CheckChanged(object sender, EventArgs e) 
        { 
            // How can I get the DataKeyNames, and the RadNumericTextBox, so I can calculate the Total 
        } 

Also, some rows will have 1 to 5 additional rows in the detail table. Say a DetailTable has 5 rows but only 2 are checked with a number in the RadNumericTextBox, how can I iterate all the rows in the DetailTables that are checked and get the DataKey names and value of RadNumericTextBox etc?

Thanks.

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jul 2009, 05:54 AM
Hi Michael,

I have implemented a similar scenario on my end and here is the code which I tried on my end. Give a try with the following code snippet and see whether it helps.

CS:
 
   <DetailTables> 
                      <telerik:GridTableView runat="server"  DataKeyNames="ItemId"   Name="Stock" > 
                       <Columns> 
                       
                        <telerik:GridTemplateColumn HeaderText="Select" UniqueName="Select"  > 
                             <ItemTemplate> 
                                 <asp:CheckBox ID="Add_CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="Add_CheckBox1_CheckedChanged" /> 
                             </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn UniqueName="UnitsQty" HeaderText="Units Qty"  > 
                             <ItemTemplate> 
                                 <telerik:RadNumericTextBox ID="Add_tbUnitsQty" runat="server"
                                 </telerik:RadNumericTextBox> 
                             </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        
                       <telerik:GridTemplateColumn UniqueName="Total" HeaderText="Total"  > 
                             <ItemTemplate> 
                                 <asp:Label ID="Add_lblTotal" runat="server" Text="Label"></asp:Label> 
                             </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                       </Columns> 
                           
                         
                   </telerik:GridTableView> 
               </DetailTables> 


CS:
 
 protected void Add_CheckBox1_CheckedChanged(object sender, EventArgs e) 
    { 
        CheckBox chkbx = (CheckBox)sender;
       
        //to get the current row
        GridDataItem item = (GridDataItem)chkbx.NamingContainer;
     
        // to access the numeric textbox from the current row
        RadNumericTextBox radtxtbx = (RadNumericTextBox)item.FindControl("Add_tbUnitsQty");
        
        //to get the DatakeyName
        int ItemId = Convert.ToInt16(item.GetDataKeyValue("ItemId").ToString()); 
        int Total = Convert.ToInt16(radtxtbx.Text.ToString()) + ItemId;
      
       //Access the label here
        Label Add_lblTotal = (Label)item.FindControl("Add_lblTotal"); 
        Add_lblTotal.Text = Total.ToString(); 
    } 


Regards
Shinu
0
Michael
Top achievements
Rank 1
answered on 22 Jul 2009, 06:20 AM
That's awesome thanks for that.

Now in addition to this, on a paged RadGrid, how do I keep the state of the DetailTable when moving from 1 page to another and then back to the page where the DetailTable is expanded and values are in there?

Is there CS code to expand a DetailTable etc?
0
Shinu
Top achievements
Rank 2
answered on 22 Jul 2009, 06:46 AM
Hi Michael,

Here is a code library submission which explains how to retain the expanded/selected state in hierarchy on rebind. Go through it and see if it helps.
Retain expanded/selected state in hierarchy on rebind

Thanks
Shinu
0
Michael
Top achievements
Rank 1
answered on 27 Jul 2009, 06:52 AM
Thanks Shinu

I downloaded that and had a look at the code. I am getting the DetailTable expanding, however I need to plug in values at the same time.

I need to set the CheckBox checked and a value in the RadNumericTextBox. I am not sure how to get this happening.

It seems when I put the datasource of the DetailGrid table, it has no items until the page is visible, so I can not iterate through each item in the code.

Also I can't seem to get the <DetailTables><telerik:GridTableView OnDataBound="THIS_FUNCTION_HERE" to fire.
It is not firing.

Thanks.

0
Michael
Top achievements
Rank 1
answered on 29 Jul 2009, 02:04 PM
Hi, can anyone help me with this issue? It much appreciated thanks.
0
Michael
Top achievements
Rank 1
answered on 30 Jul 2009, 12:47 PM
ok I am nearly there!!!! :)

Just 1 minor thing is still not working. Below is my OnDataBound code for the main RadGrid, please don't mind my hardcoded tests.

protected void Add_rgInventory_DataBound(object sender, EventArgs e) 
    foreach (GridDataItem gdi in Add_rgInventory.Items) 
    { 
        int itemId = (int)gdi.OwnerTableView.DataKeyValues[gdi.ItemIndex]["ItemId"]; 
        if ((itemId == 406) || (itemId == 411)) 
        { 
            Response.Write(itemId.ToString() + "<br />"); 
            Add_rgInventory.Items[gdi.ItemIndex].Expanded = true
            GridTableView gtv = (Add_rgInventory.Items[gdi.ItemIndexHierarchical].ChildItem.NestedTableViews[0] as GridTableView); 
            foreach (GridDataItem gdi2 in gtv.Items) 
            { 
                int campaignId = (int)gdi2.OwnerTableView.DataKeyValues[gdi2.ItemIndex]["CampaignId"]; 
                int stockOptionId = (int)gdi2.OwnerTableView.DataKeyValues[gdi2.ItemIndex]["StockOptionId"]; 
                Response.Write(itemId + " - " + campaignId + " - " + stockOptionId + "<br />"); 
 
                RadNumericTextBox Add_tbUnitsQty = (RadNumericTextBox)gdi2.FindControl("Add_tbUnitsQty"); 
                Add_tbUnitsQty.Text = itemId.ToString(); 
            } 
        } 
    } 

As you can see I hardcoded the 2 ItemId's I want the detail table to be expanded. If I only put 1 ItemId to expand, IT WORKS!!! However if I put 2 ItemId's, only the first ItemId expands and not the second :(

Does anyone have any further information on this? Thanks
0
Michael
Top achievements
Rank 1
answered on 02 Aug 2009, 11:28 PM
Hi can anyone help me with this? I am so close. Thanks.
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Aug 2009, 07:11 AM
Hello Michael,

You can try making a slight modification to your code as shown below and see if it helps:
c#:
protected void Add_rgInventory_DataBound(object sender, EventArgs e)   
{   
    foreach (GridDataItem gdi in Add_rgInventory.Items)   
    {   
        int itemId = (int)gdi.OwnerTableView.DataKeyValues[gdi.ItemIndex]["ItemId"];   
        if ((itemId == 406) || (itemId == 411))   
        {   
            Response.Write(itemId.ToString() + "<br />");   
            gdi.Expanded = true;  // replace with this line of code 
  
            GridTableView gtv = (gdi.ChildItem.NestedTableViews[0] as GridTableView);   
            foreach (GridDataItem gdi2 in gtv.Items)   
            {   
                int campaignId = (int)gdi2.OwnerTableView.DataKeyValues[gdi2.ItemIndex]["CampaignId"];   
                int stockOptionId = (int)gdi2.OwnerTableView.DataKeyValues[gdi2.ItemIndex]["StockOptionId"];   
                Response.Write(itemId + " - " + campaignId + " - " + stockOptionId + "<br />");   
   
                RadNumericTextBox Add_tbUnitsQty = (RadNumericTextBox)gdi2.FindControl("Add_tbUnitsQty");   
                Add_tbUnitsQty.Text = itemId.ToString();   
            }   
        }   
    }   
}   

Thanks
Princy.
0
Michael
Top achievements
Rank 1
answered on 03 Aug 2009, 08:48 AM
Worked thank you very much!
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or