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

Selecting from a RadioButtonList in pop-up edit mode

2 Answers 386 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 09 Jul 2008, 06:33 PM
I was wondering if anyone could tell me how to select the appropriate radio button from a radio button list located in a grid pop up edit box?  I've been searching for hours.  My code is below with the bold area on the control.  I have no problem doing text boxes, etc. using <%# Eval("variablename") %> but get really confused otherwise.  Any input would be great.  Thanks.


<telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" Width="450px" DataSourceID="SqlDataSource1"
            Skin="Hay"
            ShowStatusBar="True" GridLines="None">
            <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" />
            <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="spotlight_id" DataSourceID="SqlDataSource1" EditMode="PopUp">
                <EditFormSettings PopUpSettings-Modal="true"></EditFormSettings>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType=ImageButton>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridTemplateColumn UniqueName="active" Visible="false" HeaderText="Active">
                        <EditItemTemplate>
                            <asp:RadioButtonList id="active" runat="server">
                                <asp:ListItem Value="0">No</asp:ListItem>
                                <asp:ListItem Value="1">Yes</asp:ListItem>
                             </asp:RadioButtonList>

                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="docdate" Visible="false" HeaderText="Document Date">
                        <EditItemTemplate>
                            <telerik:RadDatePicker ID="docdate" runat="server" Skin="Hay" Calendar-Skin="Hay" Calendar-EnableNavigationAnimation="true">
                            </telerik:RadDatePicker>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>

                    <telerik:GridTemplateColumn HeaderText="Title" UniqueName="title" SortExpression="resource_name">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblTitle" Text='<%# Eval("title") %>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" Style="width: 205px; margin-left: 3px;" ID="txbTitle"
                                Text='<%# Bind("title") %>' />
                            <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbTitle"
                                ErrorMessage="Please enter a title." Display="Dynamic" SetFocusOnError="true">
                            </asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    
                    <telerik:GridTemplateColumn HeaderText="Viewable Date" UniqueName="viewabledate" SortExpression="viewabledate">
                        <ItemTemplate>
                            <asp:Label ID="lblViewableDate" runat="server" Text='<%# Eval("viewabledate") %>'>
                            </asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn ConfirmText="Are you sure you wish to delete this item?" Text="Delete" CommandName="Delete"
                        UniqueName="column" ButtonType=ImageButton>
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings EditColumn-ButtonType="ImageButton" EditColumn-InsertImageUrl="~/images/Update.gif">
                    <EditColumn UniqueName="EditCommandColumn1">
                    </EditColumn>
                    <PopUpSettings ScrollBars="None" />
                </EditFormSettings>
                <ExpandCollapseColumn Visible="False" Resizable="False">
                    <HeaderStyle Width="20px" />
                </ExpandCollapseColumn>
                <RowIndicatorColumn Visible="False">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
            </MasterTableView>
            <ClientSettings AllowRowsDragDrop="True">
                    <Selecting AllowRowSelect="True" EnableDragToSelectRows="true"/>
                    <ClientEvents OnRowDropping="onRowDropping" />
                </ClientSettings>
        </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jul 2008, 06:09 AM
Hello Derek,

Check out the following code snippet to select a radiobutton from a RadioButtonList in a GridPopUpEditForm.

ASPX:
<telerik:GridTemplateColumn UniqueName="active" HeaderText="Active"
     <EditItemTemplate> 
            <asp:RadioButtonList runat="server" id="active"
                  <asp:ListItem Value="1" Text="Yes" ></asp:ListItem> 
                  <asp:ListItem Value="0" Text="No"></asp:ListItem> 
            </asp:RadioButtonList> 
     </EditItemTemplate> 
</telerik:GridTemplateColumn>  

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
          { 
              GridEditFormItem edititem = (GridEditFormItem)e.Item; 
              RadioButtonList radbtnlist = (RadioButtonList)edititem.FindControl("active"); 
              if (radbtnlist.Items[0].Value =="1") 
               { 
                 radbtnlist.Items[0].Selected = true
               } 
          } 
    } 

Thanks
Princy.
0
Derek
Top achievements
Rank 1
answered on 10 Jul 2008, 01:15 PM
Beautiful, works perfect!  Thanks a bunch!
Tags
Grid
Asked by
Derek
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Derek
Top achievements
Rank 1
Share this question
or