I had receive the above mention error I have load printer info in first combo box and when select value a event triggered and load values in second combo box using printer info but i am receiving subject mention error.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'txtUPCode.Attributes.Add("onclick", "showDiv('divQtyAddSidebar');")
        'txtUPCode.Attributes.Add("onfocus", "showDiv('divQtyAddSidebar');")
        'txtUPCode.Attributes.Add("onblur", "hideDiv('divQtyAddSidebar', this.value);")

        txtProductSearch.Attributes.Add("onfocus", "showDiv('divSearchSidebar');")
        txtProductSearch.Attributes.Add("onblur", "hideDiv('divSearchSidebar', this.value);")



        If Not IsPostBack Then
            ''Load Brand Name
            ddlSelectBrand.DataSource = wseCommerce.LoadBrand().Tables(0)
            ddlSelectBrand.DataTextField = wseCommerce.LoadBrand().Tables(0).Columns("ManufacturerName").ColumnName.ToString()
            ddlSelectBrand.DataValueField = wseCommerce.LoadBrand().Tables(0).Columns("ManufacturerCode").ColumnName.ToString()
            ddlSelectBrand.DataBind()
        End If

        LoadPageStateFromPersistenceMedium()
    End Sub

    Protected Sub ddlSelectBrand_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSelectBrand.SelectedIndexChanged
        If ddlSelectBrand.SelectedValue <> "" Then
            ddlSelectCatridge.Enabled = True
            ddlSelectPrinter.Enabled = True

            'Load Printer against Brand Name
            Dim BrandName As String = ddlSelectBrand.SelectedItem.Text.ToString
            [B]ddlSelectPrinter.DataSource = wseCommerce.LoadPrinter(BrandName).Tables(0)[/B] 'error Object reference not set to an instance of an object. 
            ddlSelectPrinter.DataValueField = wseCommerce.LoadPrinter(BrandName).Tables(0).Columns("PrinterName").ColumnName.ToString()
            ddlSelectPrinter.DataTextField = wseCommerce.LoadPrinter(BrandName).Tables(0).Columns("PrinterName").ColumnName.ToString()
            ddlSelectPrinter.DataBind()
        Else
            ddlSelectCatridge.Enabled = False
            ddlSelectPrinter.Enabled = False
        End If
    End Sub

Recommended Answers

All 2 Replies

Try to remove .ToString from:

'Load Printer against Brand Name
Dim BrandName As String = ddlSelectBrand.SelectedItem.Text.ToString

I don't think ToString() is the problem..
You just make sure that your ddlSelectBrand.SelectedItem.Text retrurn BrandName. If it's returning the BrnadName than debugg the wseCommerce.LoadPrinter(BrandName).Tables(0) method and make sure it returns the DataSet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.