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

[Solved] Can't get RadComboBox values from RadGrid

3 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 21 Apr 2013, 07:42 PM

I've tried everything, can't seem to get the value of a EditItemTemplate that holds a radComboBox.  I have my grid setup like this:

<telerik:RadGrid ID="RadGrid1" GridLines="Both" AutoGenerateColumns="False"
                                    AllowPaging="True" AllowSorting="True" runat="server" OnItemDataBound="OnItemDataBoundHandler"
                                    OnInsertCommand="RadGrid1_InsertCommand" OnItemCreated="RadGrid1_ItemCreated"
                                    DataSourceID="DeliverableDataSource" AllowAutomaticUpdates="False" AllowAutomaticInserts="False" AllowAutomaticDeletes="false"
                                    ShowStatusBar="True" CellSpacing="0" OnUpdateCommand="RadGrid1_UpdateCommand" OnDeleteCommand="RadGrid1_DeleteCommand" Width="900px">
                                    <MasterTableView ShowFooter="false" EditMode="InPlace" CommandItemDisplay="Top">
                                        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

                                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>

                                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="DeliverableID" DataType="System.Int32" Visible="false" FilterControlAltText="Filter DeliverableID column" HeaderText="DeliverableID" ReadOnly="True" SortExpression="DeliverableID" UniqueName="DeliverableID">
                                            </telerik:GridBoundColumn>

                                            <telerik:GridTemplateColumn HeaderText="Deliverable Type" HeaderStyle-Font-Bold="true" ItemStyle-Width="240px">
                                                <ItemTemplate>
                                                    <%#DataBinder.Eval(Container.DataItem, "DeliverableType")%>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <telerik:RadComboBox runat="server" EnableLoadOnDemand="true" ID="cmbType" DataTextField="DeliverableTypeDesc"
                                                        DataValueField="DeliverableTypeDesc" DataSourceID="DeliverableTypeDataSource" SelectedValue='<%#Bind("DeliverableType") %>'>
                                                    </telerik:RadComboBox>
                                                </EditItemTemplate>
                                                <HeaderStyle Font-Bold="True" />
                                                <ItemStyle Width="140px" />
                                            </telerik:GridTemplateColumn>

                                            <telerik:GridTemplateColumn HeaderText="Deliverable User" ItemStyle-Width="240px" HeaderStyle-Font-Bold="true">
                                                <ItemTemplate>
                                                    <%#DataBinder.Eval(Container.DataItem, "DeliverableUser")%>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <telerik:RadComboBox runat="server" ID="cmbUser" DataTextField="UserName" SelectedValue='<%#Bind("DeliverableUser") %>'
                                                        DataValueField="UserName" DataSourceID="UserDataSource">
                                                    </telerik:RadComboBox>
                                                </EditItemTemplate>
                                                <HeaderStyle Font-Bold="True" />
                                                <ItemStyle Width="140px" />
                                            </telerik:GridTemplateColumn>

                                            <telerik:GridTemplateColumn DataField="Verdict" HeaderText="Verdict" HeaderStyle-Font-Bold="true" UniqueName="Verdict">
                                                <ItemTemplate>
                                                    <%#DataBinder.Eval(Container.DataItem, "Verdict")%>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <telerik:RadComboBox runat="server" ID="cmbVerdict" SelectedValue='<%#Bind("Verdict") %>'>
                                                        <Items>
                                                            <telerik:RadComboBoxItem Text=" " Value=" " />
                                                            <telerik:RadComboBoxItem Text="Accepted" Value="Accepted" />
                                                            <telerik:RadComboBoxItem Text="Rejected" Value="Rejected" />
                                                        </Items>
                                                    </telerik:RadComboBox>
                                                </EditItemTemplate>
                                                <HeaderStyle Font-Bold="True" />
                                                <ItemStyle Width="100px" />
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn" ButtonType="ImageButton" EditImageUrl="~/Images/DeviationEdit.png"
                                                HeaderText="" HeaderStyle-Width="80px" UpdateText="Save" UpdateImageUrl="~/Images/DeviationSave.jpg" CancelImageUrl="~/Images/DeviationCancel.jpg" InsertImageUrl="~/Images/DeviationSave.jpg">
                                                <HeaderStyle Width="50px" />
                                            </telerik:GridEditCommandColumn>
                                            <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ImageUrl="~/Images/DeviationDelete.jpg" ButtonType="ImageButton" UniqueName="deleteColumn">
                                                <HeaderStyle Width="30px"></HeaderStyle>
                                            </telerik:GridButtonColumn>

                                        </Columns>

                                        <EditFormSettings>
                                            <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>

                                    <FilterMenu EnableImageSprites="False"></FilterMenu>
                                </telerik:RadGrid>




I want to hit a button that is not part of the radGrid, and from code behind, I want to get the selected Value from the cmbVerdict column for every row in the grid.  Something like this:

            foreach (GridDataItem item in RadGrid1.Items)
            {                               
                RadComboBox cmbV = (RadComboBox)item.FindControl("cmbVerdict");
                ....
            }
This always return null.  I've tried 7000 different combinations from the hundreds of posts.  Nothing seems to work.  Please help.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2013, 04:20 AM
Hi,

Try the following.
C#:
foreach (GridEditableItem item in RadGrid2.EditItems)
 {
      RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
}

Thanks,
Shinu
0
Jeff
Top achievements
Rank 1
answered on 22 Apr 2013, 11:53 AM
When I run the code above, it never gets into the for each block, the count of RadGrid1.EditItems is Zero.

0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Apr 2013, 01:15 PM
Hello,


I am not able to reproduce this issue.

I have checked with below code snippet.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[StudentDetails](
    [StudentID] [int] NOT NULL,
    [StudentName] [varchar](15) NULL,
PRIMARY KEY CLUSTERED
(
    [StudentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[StudentDetails] ([StudentID], [StudentName]) VALUES (1, N'SMITH')
INSERT [dbo].[StudentDetails] ([StudentID], [StudentName]) VALUES (2, N'ALLEN')
INSERT [dbo].[StudentDetails] ([StudentID], [StudentName]) VALUES (3, N'JONES')
INSERT [dbo].[StudentDetails] ([StudentID], [StudentName]) VALUES (4, N'MARTIN')
INSERT [dbo].[StudentDetails] ([StudentID], [StudentName]) VALUES (5, N'JAMES')
<connectionStrings>
  <add name="JayeshTestConnectionString" connectionString="Data Source=PC222\SQL2008;Initial Catalog=JayeshTest;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
  </telerik:RadScriptManager>
  <telerik:RadGrid ID="RadGrid1" GridLines="Both" AutoGenerateColumns="False" AllowPaging="True"
      AllowSorting="True" runat="server" DataSourceID="SqlDataSource1" AllowAutomaticUpdates="False"
      AllowAutomaticInserts="False" AllowAutomaticDeletes="false" ShowStatusBar="True"
      CellSpacing="0" Width="900px">
      <MasterTableView ShowFooter="false" EditMode="InPlace" CommandItemDisplay="Top">
          <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
          <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
          </RowIndicatorColumn>
          <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
          </ExpandCollapseColumn>
          <Columns>
              <telerik:GridBoundColumn DataField="StudentID" DataType="System.Int32" FilterControlAltText="Filter StudentID column"
                  HeaderText="StudentID" ReadOnly="True" SortExpression="StudentID" UniqueName="StudentID">
              </telerik:GridBoundColumn>
              <telerik:GridTemplateColumn HeaderText="Verdict" HeaderStyle-Font-Bold="true" UniqueName="Verdict">
                  <EditItemTemplate>
                      <telerik:RadComboBox runat="server" ID="cmbVerdict">
                          <Items>
                              <telerik:RadComboBoxItem Text=" " Value=" " />
                              <telerik:RadComboBoxItem Text="Accepted" Value="Accepted" />
                              <telerik:RadComboBoxItem Text="Rejected" Value="Rejected" />
                          </Items>
                      </telerik:RadComboBox>
                  </EditItemTemplate>
                  <HeaderStyle Font-Bold="True" />
                  <ItemStyle Width="100px" />
              </telerik:GridTemplateColumn>
              <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
                  ButtonType="ImageButton" HeaderText="" HeaderStyle-Width="80px" UpdateText="Save">
                  <HeaderStyle Width="50px" />
              </telerik:GridEditCommandColumn>
              <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ImageUrl="~/Images/DeviationDelete.jpg"
                  ButtonType="ImageButton" UniqueName="deleteColumn">
                  <HeaderStyle Width="30px"></HeaderStyle>
              </telerik:GridButtonColumn>
          </Columns>
          <EditFormSettings>
              <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column">
              </EditColumn>
          </EditFormSettings>
      </MasterTableView>
      <FilterMenu EnableImageSprites="False">
      </FilterMenu>
  </telerik:RadGrid>
  <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>"
      SelectCommand="SELECT [StudentID], [StudentName] FROM [StudentDetails]"></asp:SqlDataSource>
protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridEditableItem item in RadGrid1.EditItems)
       {
           RadComboBox combo = (RadComboBox)item.FindControl("cmbVerdict");
       }
   }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or