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

Initial Value to RadCombobox in a filter

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gdelatolas
Top achievements
Rank 1
gdelatolas asked on 07 Oct 2010, 03:40 PM

Dear Telerik,

We have a RadcomboBox in a filter template and we put an default value using the following code

 

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
    RadGrid1.MasterTableView.FilterExpression = "([UserName] like '" + Session("UserName") + "%' )"
End Sub
  
  
Protected Sub RadComboBoxUserName_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs)
    If Not Me.IsPostBack Then
        If e.Item.Text = Session("UserName") Then
            e.Item.Selected = True
        End If
    End If
End Sub

 

 

 

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     
  
    <br />
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" EnableLinqExpressions="False"
        DataSourceID="SqlDataSource1" GridLines="None" Skin="Hay" PageSize="30" 
        AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" 
        OnEditCommand="RadGrid1_EditCommand" >
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
        </ClientSettings>
        <MasterTableView datakeynames="PMID" datasourceid="SqlDataSource1" 
            commanditemdisplay="Top" PageSize="25">
        <RowIndicatorColumn><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>
        <ExpandCollapseColumn><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn>
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <Columns>
            <telerik:GridTemplateColumn UniqueName="TemplateColumn" AllowFiltering="False">
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Προβολή" 
                        CommandName="Edit" ImageUrl="~/images/edt.gif" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="PMID" DataType="System.Decimal" 
                HeaderText="Κωδικός" ReadOnly="True" SortExpression="PMID" UniqueName="PMID">
                <HeaderStyle HorizontalAlign ="Center" />
                <ItemStyle HorizontalAlign ="Center" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CName" HeaderText="Πελάτης" 
                SortExpression="CName" UniqueName="CName" 
                AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CAddr" HeaderText="Διεύθυνση" 
                SortExpression="CAddr" UniqueName="CAddr" 
                AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CCity" HeaderText="Πόλη" SortExpression="CCity" UniqueName="CCity" 
                AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn AutoPostBackOnFilter="True" 
                DataField="ProposalDate" DataType="System.DateTime" 
                HeaderText="Ημερ/νία Προσφοράς" SortExpression="ProposalDate" 
                UniqueName="ProposalDate">
                <ItemTemplate>
                    <asp:Label ID="ProposalDateLabel" runat="server" 
                        Text='<%# Eval("ProposalDate", "{0:dd/MM/yyyy}") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn AutoPostBackOnFilter="false" DataField="PSStatus" 
                HeaderText="Κατάσταση" UniqueName="PSStatus" ReadOnly="True">
                <FilterTemplate>
                    <telerik:RadComboBox ID="RadComboPStatus" DataSourceID="SqlDataSource2" DataTextField="PSStatus"
                        DataValueField="PSStatus" Height="100px" AppendDataBoundItems="true" 
                        SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("PSStatus").CurrentFilterValue %>'
                        runat="server" OnClientSelectedIndexChanged="CityIndexChanged">
                        <Items>
                            <telerik:RadComboBoxItem Text="'Ολα" />
                        </Items>
                    </telerik:RadComboBox>
                              
                    <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
                        <script type="text/javascript">
                            function CityIndexChanged(sender, args) {
                                var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                                tableView.filter("PSStatus", args.get_item().get_value(), "EqualTo");
                            }
                        </script>
  
                    </telerik:RadScriptBlock>
  
                </FilterTemplate>
                <HeaderStyle HorizontalAlign ="Center" />
                <ItemStyle HorizontalAlign ="Center" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="UserName" HeaderText="Χρήστης" UniqueName="UserName">
                <FilterTemplate>
                    <telerik:RadComboBox ID="RadComboBoxUserName" DataSourceID="SqlDataSource3" DataTextField="username" AutoPostBackOnFilter="false" 
                                DataValueField="username"  Height="200px" AppendDataBoundItems="true"  SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("UserName").CurrentFilterValue %>'
                                runat="server" 
                                OnClientSelectedIndexChanged="TitleIndexChanged" 
                                OnItemDataBound="RadComboBoxUserName_ItemDataBound" >
                                <Items>
                                    <telerik:RadComboBoxItem Text="'Ολοι" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
  
                                <script type="text/javascript">
                                    function TitleIndexChanged(sender, args) {
                                        var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                                        tableView.filter("UserName", args.get_item().get_value(), "EqualTo");
  
                                    }
                                </script>
  
                            </telerik:RadScriptBlock>
  
                </FilterTemplate>
                <HeaderStyle HorizontalAlign ="Center" />
                <ItemStyle HorizontalAlign ="Center" />
            </telerik:GridBoundColumn>
        </Columns>
        <CommandItemTemplate>
            <asp:LinkButton ID="FldNew" Text="Νέα Προσφορά" runat="server" Font-Underline="true"
                onclick="FldNew_Click" Font-Bold="True"></asp:LinkButton>
        </CommandItemTemplate>
        </MasterTableView>
        <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
            Font-Strikeout="False" Font-Underline="False" ForeColor="White" Wrap="True" />
    </telerik:RadGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AlarmConfigurator %>" 
        SelectCommand="select * from dbo.ProposalMasterView where DealerCode=@DealerCode order by PMID Desc">
        <SelectParameters>
            <asp:ControlParameter ControlID="FldDealerCode" 
                ConvertEmptyStringToNull="False" Name="DealerCode" PropertyName="Value" />
        </SelectParameters>
    </asp:SqlDataSource>     
    <asp:HiddenField ID="FldDealerCode" runat="server" />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AlarmConfigurator %>" 
        SelectCommand="select PSID,PSStatus  from dbo.StatusMaster">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AlarmConfigurator %>"           
        SelectCommand="select username, userID from Users where  DealerCode=@DealerCode ">
           
        <SelectParameters>
            <asp:ControlParameter ControlID="FldDealerCode" Name="DealerCode" 
                PropertyName="Value" />
        </SelectParameters>
    </asp:SqlDataSource>
    <telerik:RadAjaxManager runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="SqlDataSource2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
</asp:Content>

 

 

The code works, but the first time we enter a value to another filter item the combo is loosing its default value. Then if manually select an item from the filter combo, it works fine.

Any support to resolve this issue is welcome.

Than you
George

 

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 07 Oct 2010, 07:09 PM
Aside from adding the filter to the FilterExpression, you should also add it to the CurrentFilterValue property for that column. Like so:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) 
    RadGrid1.MasterTableView.FilterExpression = "([UserName] like '" + Session("UserName") + "%' )" 
    RadGrid1.MasterTableView.GetColumn("UserName").CurrentFilterValue = Session("UserName")
End Sub

I hope that helps.
0
gdelatolas
Top achievements
Rank 1
answered on 08 Oct 2010, 05:05 AM
Sorry to say but its not enough. No change in the situation.
0
Iana Tsolova
Telerik team
answered on 13 Oct 2010, 02:26 PM
Hello gdelatolas,

I suggest that you set the RadComboBox value on its PreRender event instead of on ItemDataBound based on the value stored in the Session field. Then you can handle the grid ItemCommand to change the value of the Session field when RadComboBox selection changes.

Check it out and let me know if you need further help.

All the best,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
gdelatolas
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
gdelatolas
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or