Help finding controls inside gridboundcolumn

2 posts, 0 answers
  1. ssg
    ssg avatar
    1 posts
    Member since:
    May 2014

    Posted 24 May 2014 Link to this post

    New to telerik ... Please help me finding my controls (which i have added during runtime) inside gridboundcolumn...

    This is my code snippet... I really appreciate your response...

    <telerik:RadGrid ID="gdCases" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" EnableViewState ="True" Skin="Metro" OnItemDataBound="gdCases_ItemDataBound" OnItemCreated ="gdCases_ItemCreated" OnPreRender ="gdCases_PreRender" AllowMultiRowEdit="True"><br><br>                        <MasterTableView EditMode="InPlace" DataKeyNames ="idCase,ComplaintStatus"><br>                            <CommandItemSettings ShowAddNewRecordButton="False" /><br>                            <Columns><br>                                <telerik:GridBoundColumn DataField="Tenant" FilterControlAltText="Filter colTenant column" HeaderText="Apt/Tenant" UniqueName="colTenant" ReadOnly="True"><br>                                    <HeaderStyle Font-Names="Tahoma" Font-Size="Small" HorizontalAlign="Center" Width="120px" /><br>                                </telerik:GridBoundColumn><br>                               <br>                                <telerik:GridBoundColumn DataField="ComplaintStatus" FilterControlAltText="Filter colStatus column" HeaderText="Continue ?" UniqueName="colStatus" ReadOnly="True"><br>                                    <HeaderStyle HorizontalAlign="Center" Width="120px" /><br>                                    <ItemStyle HorizontalAlign="Center" /><br>                                </telerik:GridBoundColumn><br>                                <telerik:GridBoundColumn DataField="TotalArrearage" FilterControlAltText="Filter colLastOwed column" HeaderText="Last Owed" UniqueName="colLastOwed" ReadOnly="True"><br>                                    <HeaderStyle Font-Names="Tahoma" Font-Size="Small" HorizontalAlign="Center" Width="120px" /><br>                                    <ItemStyle HorizontalAlign="Right" /><br>                                </telerik:GridBoundColumn><br>                                <telerik:GridBoundColumn DataField="ComplaintTotalOwed" FilterControlAltText="Filter colCurrentOwed column" HeaderText="Current Owed" UniqueName="colCurrentOwed" EmptyDataText=""><br>                                    <HeaderStyle Font-Names="Tahoma" Font-Size="Small" HorizontalAlign="Center" Width="120px"  /><br>                                    <ItemStyle HorizontalAlign="Right" /><br>                                </telerik:GridBoundColumn><br>                                <telerik:GridBoundColumn DataField="idCase" Display="False" FilterControlAltText="Filter colCase column" UniqueName="colCase"><br>                                    <HeaderStyle Width="1px" /><br>                                    <ItemStyle Font-Names="Tahoma" Font-Size="Small" HorizontalAlign="Right" /><br>                                </telerik:GridBoundColumn><br>                            </Columns><br>                        </MasterTableView><br>                    </telerik:RadGrid><br>

    in aspx.cs

      protected void gdCases_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
            {
                if (e.Item is GridEditableItem && e.Item is GridDataItem)
                {
                    GridEditableItem item = (GridEditableItem)e.Item;

                    RadioButton rdoYes = new RadioButton();
                    rdoYes.Text = "Yes";
                    rdoYes.GroupName = "group1";

                    RadioButton rdoNo = new RadioButton();
                    rdoNo.Text = "No";
                    rdoNo.GroupName = "group1";
                    if (item["colStatus"].Text == "Continue")
                        rdoYes.Checked = true;
                    else
                        rdoNo.Checked = false;
                  
                    item["colStatus"].Controls.Add(rdoYes);
                    item["colStatus"].Controls.Add(rdoNo);
                    TextBox totalOwed = new TextBox();
                    totalOwed.Style["text-align"] = "right";
                    totalOwed.Width = 120;

                    if (item["colCurrentOwed"].Text != "")
                        totalOwed.Text = item["colCurrentOwed"].Text.Trim();
                    else
                        totalOwed.Text = String.Empty;
                    totalOwed.Text.Replace("&nbsp;", String.Empty);
                    item["colCurrentOwed"].Controls.Add(totalOwed);

                }
            }
    On btnClick - Save 

          protected void btnSave_Click(object sender, EventArgs e)
            {
              
                foreach (GridDataItem item in gdCases.MasterTableView.Items) 
                {

                    TableCell cellCurrentOwed = item["colCurrentOwed"];
                    string totalOwed = (cellCurrentOwed.Controls[0] as TextBox).Text; --GETTING ERROR
                    TableCell cellColStatus = item["colStatus"];
                    
                    RadioButton rdoY = (RadioButton)item.FindControl("rdoYes"); --GETTING ERROR
                    TableCell cellStatus = item["colStatus"];
                    Boolean statusChecked = (cellStatus.Controls[0] as RadioButton).Checked;  --GETTING ERROR
                    String itemStatus = "";

                    if (statusChecked)
                        itemStatus = "Continue";
                    else
                        itemStatus = "Discontinue"; 







  2. Kostadin
    Admin
    Kostadin avatar
    1709 posts

    Posted 28 May 2014 Link to this post

    Hi Ssg,

    I noticed that you are adding some controls in the GridBoundColumn OnItemDataBound event handler. Note that those controls will not be saved in the ViewState and after rebind they will be lost. If you want to add a controls in a grid column then I would recommend you to use a GridTemplateColumn. You can find more information about this column type at the following help article and the following help topic describes how to access its controls.

    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top