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

Drop Down List in RadGrid

4 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 28 May 2014, 01:04 AM
Hi,

I am trying to get a RadDropDownList to work within a RadGrid. Autogeneratecolumns are set to False and all columns have been set.

The first code snippet is the column I am having issues with. The second code snippet is the same column but doesn't offer the DropDownList feature.
Basically what I am trying to archive, is when a user is looking at the grid, they can easily change the "Team" without the need going to Edit > (Change record) > Update.

​<telerik:GridTemplateColumn>                  <ItemTemplate>                                               <telerik:RadDropDownList DataField="IDNO" DataSourceID="TeamFilterOptions"                                                  HeaderText="123" DataTextField="FieldAnswer"                                                   UniqueName="DocCategoryColumn3" runat="server" ID="ddlEditCategory" AutoPostBack="True"></telerik:RadDropDownList>                  </ItemTemplate>              </telerik:GridTemplateColumn>
 
 
 
 
 



<telerik:GridBoundColumn DataField="Team" HeaderText="Team" UniqueName="Team">                                            <FilterTemplate>                                               <telerik:RadComboBox ID="RadListBoxTeam" DataSourceID="TeamFilterOptions" DataTextField="FieldAnswer"                            DataValueField="FieldAnswer" Height="200px" AppendDataBoundItems="true" SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("Team").CurrentFilterValue %>'                            runat="server" OnClientSelectedIndexChanged="TeamIndexChange">                            <Items>                                <telerik:RadComboBoxItem Text="All" />                            </Items>                        </telerik:RadComboBox>                         <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">                            <script type="text/javascript">                                function TeamIndexChange(sender, args) {                                    var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID%>");                                    tableView.filter("Team", args.get_item().get_value(), "EqualTo");                                }                            </script>                        </telerik:RadScriptBlock>                    </FilterTemplate>                </telerik:GridBoundColumn>





My issues I am facing are 
How do I get the item to display the correct text as it just displays the first record from the data source. i.e. pull the data from the RadGrid datasource, the DataTextField should get the "Team" field. When I try to bind the data it just says "System.Data.DataRowView".
Once the user changes the value from the Drop Down List how do I retrieve that value in the code behind (VB.net but C# is fine), I cannot find anything relating to CommandName?

Thanks,
Alex



4 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 28 May 2014, 01:13 AM
Coming to think about it actually, do you think I would be best using GridDropDownColumn instead? Will this let me get the results I need e.g. changing directly from the grid?

Thanks,
0
Shinu
Top achievements
Rank 2
answered on 28 May 2014, 06:34 AM
Hi Alex,

Since you want to have the DropDown to update in view mode GridTemplateColumn is better, when in browser mode, GridDropDownColumn looks and behaves like a standard GridBoundColumn. You can try the following code snippet to set the selected value for the row and attach the OnSelectedIndexChanged event to get the selected text.

ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <telerik:RadDropDownList ID="ddlEditCategory" AutoPostBack="True" OnSelectedIndexChanged="ddlEditCategory_SelectedIndexChanged1" . .>
        </telerik:RadDropDownList>
    </ItemTemplate>
</telerik:GridTemplateColumn>

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim rddlTeam As RadDropDownList = DirectCast(dataItem.FindControl("ddlEditCategory"), RadDropDownList)
        'sets the row value
        rddlTeam.SelectedItem.Text = DataBinder.Eval(dataItem.DataItem, "FieldAnswer").ToString()
    End If
End Sub
 
Protected Sub ddlEditCategory_SelectedIndexChanged1(sender As Object, e As DropDownListEventArgs)
    Dim rddlTeam As RadDropDownList = DirectCast(sender, RadDropDownList)
    'Get the selected text
    Dim selectedText As String = rddlTeam.SelectedText
End Sub

Thanks,
Shinu
0
Alex
Top achievements
Rank 1
answered on 28 May 2014, 06:13 PM
Hi Shinu,

Thanks for the reply. I will give that a go.

I do have two other things if you could help me out with that as well please.

When filtering is turned on for the RADGrid, how do I use the filter templates to create one which allows multiple filtering e.g. a Drop Down List with checkboxes on a single column.
Then, how do I implement the drop down list with check boxes in the GridTemplate Column when in view mode (so it can be auto updated like the code you posted before) ?

Thanks again,
Alex 

Thanks,
0
Shinu
Top achievements
Rank 2
answered on 29 May 2014, 06:22 AM
Hi Alex,

You can refer this CodeLibrary on Multi-Selection RadComboBox for filtering grid which will help you to achieve your first requirement.

To have DropDown with checkbox you can use ItemTemplate of the RadDropDownList as shown below:

ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
      <telerik:RadDropDownList. . .>
          <ItemTemplate>
           <asp:CheckBox ID="chkAns" runat="server" />
           <asp:Label ID="lblAns" runat="server" Text='<%#Eval("FieldAnswer") %>'></asp:Label>
          </ItemTemplate>
      </telerik:RadDropDownList>
    </ItemTemplate>
</telerik:GridTemplateColumn>

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