Problem setting SelectedItem.Value in combobox v2.0

Page 1 of 2 12 LastLast
  1. #1

    Problem setting SelectedItem.Value in combobox v2.0

    Hello!

    After convert an application to version 2.0 I'm having problem to set a particular value to a combobox. When I try to set a value I received a message about Object Instance null exception (System.NullReferenceException).

    My combobox code:

                        <ext:ComboBox ID="dbAtivo" runat="server" Editable="false" Height="20px"
                            FieldLabel="Ativo" Width="300px" ReadOnly="true" >
                            <Items>
                                <ext:ListItem Text="Yes" Value="Y" />
                                <ext:ListItem Text="No" Value="N" />
                            </Items>
                        </ext:ComboBox>
    Code to set a value from database:

                    dbAtivo.SelectedItem.Value = drSql.GetString(4);
    Thanks in advance!
  2. #2
    Hi,

    Please use:
    ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "some value" });
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Please use:
    ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "some value" });
    Hi Daniil,

    Thanks for help, it works. I tried another code using Combobox1.SetValue(some value) and works too.

    You can mark as closed.

    Thanks.

    Oliver
  4. #4
    Quote Originally Posted by Daniil View Post
    Hi,

    Please use:
    ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "some value" });
    Hi Daniil,

    i m facing the same issue. what i m trying to do is, i have a combobox displaying list of say employees, i've set Code as ValueField and Name as DisplayField for the Combobox. i m using asp.net with VB so i m not able try your above stated solution. (don't know how to use it in VB).
    i store Employee Code to the database and not Name. and after retrieving the data from database i want to set the name related to code in database as selected item.

    i've also tried using ComboBox1.SetValue, but it sets code as text and not selected value.

    thanks in advance.
  5. #5
    Quote Originally Posted by hemantpatil View Post
    Hi Daniil,

    i m facing the same issue. what i m trying to do is, i have a combobox displaying list of say employees, i've set Code as ValueField and Name as DisplayField for the Combobox. i m using asp.net with VB so i m not able try your above stated solution. (don't know how to use it in VB).
    i store Employee Code to the database and not Name. and after retrieving the data from database i want to set the name related to code in database as selected item.

    i've also tried using ComboBox1.SetValue, but it sets code as text and not selected value.

    thanks in advance.
    Here is a C# to VB converter http://converter.telerik.com/

    C#
    ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Value = "some value" });
    VB
    ComboBox1.SelectedItems.Add(New Ext.Net.ListItem() With { _
    	Key .Value = "some value" _
    })
    Last edited by blueworld; Aug 23, 2013 at 9:22 AM.
  6. #6
    Please find below code for reference.

    what i want to do is, set Dept. 2 as selected record on click of button. it's value is 2 and i want to set it with value only not text.

    ComboBox.aspx
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ComboBox.aspx.vb" Inherits="ComboBox" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <div>
            <ext:ComboBox ID="ComboBox1"
                runat="server"
                FieldLabel="Select a single Company"
                ValueField="CODE"
                DisplayField="NAME"
                Width="600"
                LabelWidth="130"
                QueryMode="Local"               
                TypeAhead="true">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="CODE" />
                                    <ext:ModelField Name="NAME" /> 
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <asp:Button ID="Button1" runat="server" Text="Button" />        
        </div>
        </form>
    </body>
    </html>
    ComboBox.aspx.vb
    Imports System.Web.UI.WebControls
    Imports System.Configuration
    
    Imports ext1 = Ext.Net
    Imports Ext.Net
    Imports Ext.Net.JSON
    
    Partial Public Class ComboBox
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Me.Store1.DataSource = Me.DeptData
            Me.Store1.DataBind()
        End Sub
    
        Private ReadOnly Property DeptData() As Object()
            Get
                Return New Object() {New Object() {1, "Dept. 1"}, New Object() {2, "Dept. 2"}, New Object() {3, "Dept. 3"}, New Object() {4, "Dept. 4"}}
            End Get
        End Property
    
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            ComboBox1.SelectedItems.Add(New Ext.Net.ListItem("2").Mode = ParameterMode.Value)
        End Sub
    End Class
    Thanks in advance.
  7. #7
    This appears to be working.
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As Ext.Net.ListItem = New Ext.Net.ListItem("2")
        s.Mode = ParameterMode.Raw
        ComboBox1.SelectedItems.Add(s)
    End Sub
  8. #8
    Hi Dannil,

    Thanks for you Reply. your solution worked for me.

    my finding regarding this method is, if you try to use this code on click or direct click of Ext.Net Button, it will not work. it works on click of Asp Button only. this is FYI only.

    you can close this thread.
  9. #9
    With a DirectEvent it should be:
    Dim s As Ext.Net.ListItem = New Ext.Net.ListItem("2")
    s.Mode = ParameterMode.Raw
    ComboBox1.SelectedItems.Add(s)
    ComboBox1.UpdateSelectedItems()
  10. #10
    Hi Dannil,

    Thanks for your quick reply.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Problem to show SelectedItem in Combobox v2.0
    By Oliver in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 28, 2012, 3:56 PM
  2. Replies: 2
    Last Post: Mar 03, 2012, 3:33 PM
  3. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  4. ComboBox SelectedItem according to Value problem
    By juredecman in forum 1.x Help
    Replies: 0
    Last Post: Aug 25, 2010, 8:57 PM
  5. Replies: 4
    Last Post: Feb 02, 2010, 4:08 PM

Posting Permissions