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

server side select radcomboboxitem

1 Answer 122 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Fredrick Zilz
Top achievements
Rank 1
Fredrick Zilz asked on 16 Jan 2009, 07:42 PM
Not sure what I am missing:

I have a radcombobox - "box1"   It is populated from a dataset.  my page_load sub looks to to see if Request.querystring("terr")  contains data.  If it does I want to look at my combobox items and see if one of the items value is the same as the the querystring.  if so, I want to change to the selection to that item.

my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        If Not Page.IsPostBack Then  
            box1.SelectedIndex = 0 
            If Not Request.QueryString("terr") Is Nothing Then  
                Dim myterr As String  
                myterr = Server.UrlDecode(Request.QueryString("terr"))  
 
 
                For Each item As RadComboBoxItem In box1.Items  
                    myterr = myterr & " - " & item.Value  
                    If Trim(item.Value) = Trim(myterr) Then  
 
                        item.Selected = True 
                    End If  
                Next  
                Label2.Text = myterr 
                ' box1.SelectedValue = Request.QueryString("terr")  
            Else  
                Label2.Text = " " 
            End If  
 
        End If 

I added a label to try and figure out what is going on, and it appears that my code for looking through the items in box1 is in correct as no item values are being appended to my label.

ASPX code:
<%@ Page Language="VB" MasterPageFile="~/SalesTools.master" AutoEventWireup="false" CodeFile="prospects.aspx.vb"  Inherits="prospects" title="Prospects" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
    &nbsp;<telerik:RadComboBox  ID="RadioButtonList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource2" DataTextField="CODETERR" DataValueField="CODETERR" 
        RepeatDirection="Horizontal"  Skin="Hay" > 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </telerik:RadComboBox > 
     
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
    &nbsp;  
    <asp:GridView ID="gvProspects" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" 
        DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" EnableTheming="True" GridLines="Horizontal" SkinID="prospectgrid">  
        <Columns> 
            <asp:TemplateField InsertVisible="False" ShowHeader="False">  
                <EditItemTemplate> 
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" 
                        Text="Update"></asp:LinkButton> 
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" 
                        Text="Cancel"></asp:LinkButton> 
                </EditItemTemplate> 
                  
                <ItemTemplate> 
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" 
                        Text="Edit"></asp:LinkButton> 
                </ItemTemplate> 
            </asp:TemplateField> 
            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" InsertVisible="False" 
                ReadOnly="True" SortExpression="CustomerID" /> 
            <asp:TemplateField HeaderText="NameCust" SortExpression="NameCust">  
                <EditItemTemplate> 
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NameCust") %>'></asp:TextBox> 
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("NameCust") %>'></asp:Label> 
                </ItemTemplate> 
                  
            </asp:TemplateField> 
        </Columns> 
        <FooterStyle BackColor="White" ForeColor="#333333" /> 
        <RowStyle BackColor="White" ForeColor="#333333" /> 
        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /> 
        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /> 
        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" /> 
    </asp:GridView> 
    <asp:Panel ID="Panel1" runat="server" Height="50px" Width="548px">  
        <asp:Button ID="Button1" runat="server" Text="New Prospect" ValidationGroup="insertCust" /> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox2" 
            ErrorMessage="Prospect Name can not be blank" ValidationGroup="insertCust"></asp:RequiredFieldValidator> 
        <asp:TextBox ID="TextBox2" runat="server" Width="330px" ValidationGroup="insertCust"></asp:TextBox></asp:Panel> 
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AccPac2ConnectionString %>" 
        SelectCommand="Select ter.CODETERR from &#13;&#10;((SELECT DISTINCT CODETERR FROM dbo.F_arcus() AS F_arcus_1 WHERE (DATELASTIV > dbo.Accpacdate(DATEADD(yyyy, - 1, GETDATE()))) AND (CODETERR <> ''))&#13;&#10;union&#13;&#10;(select 'IH')) ter">  
    </asp:SqlDataSource> 
    <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server" Skin="Web20" /> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AccPac2ConnectionString %>" 
        InsertCommand="INSERT INTO dbo.BudgetProspects(NameCust, CodeTerr) VALUES (@Namecust, @codeterr)" 
        SelectCommand="SELECT CustomerID, NameCust FROM dbo.BudgetProspects WHERE (CodeTerr = @codeterr)" 
        UpdateCommand="UPDATE dbo.BudgetProspects SET NameCust = @namecust &#13;&#10;where customerID = @customerid">  
        <UpdateParameters> 
            <asp:Parameter Name="namecust" /> 
            <asp:Parameter Name="customerid" /> 
        </UpdateParameters> 
        <SelectParameters> 
            <asp:ControlParameter ControlID="RadioButtonList1" Name="codeterr" PropertyName="SelectedValue" /> 
        </SelectParameters> 
        <InsertParameters> 
<asp:ControlParameter ControlID="textbox2" Name="Namecust" PropertyName="text" /> 
             <asp:ControlParameter ControlID="RadioButtonList1" Name="codeterr" PropertyName="SelectedValue" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 
</asp:Content> 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jan 2009, 07:26 AM
Hi Fredrick,

I am not sure that why you are adding the myterr with item.value everytime. I tried the scenario without this line of code and this working fine on my end. Please try the following code and see whether it's working on your side also.

VB:
Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) 
    If Not Page.IsPostBack Then 
        box1.SelectedIndex = 0 
        If (Request.QueryString("terr") IsNot NothingThen 
            Dim myterr As String = Nothing 
            myterr = Server.UrlDecode(Request.QueryString("terr")) 
            For Each item As RadComboBoxItem In box1.Items 
                If item.Value = myterr Then 
                    item.Selected = True 
                End If 
            Next 
        End If 
    End If 
End Sub 

You can also try the below code for setting the RadComboBoxItem as selected.

VB:
box1.SelectedValue = Request.QueryString("terr"

Thanks,
Shinu.
Tags
ComboBox
Asked by
Fredrick Zilz
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or