Welcome to Sign in | Help
in Search

Ajutor - ListBox VisualStudio ASP.Net

Last post 03-09-2010, 4:04 PM by hyghnet. 10 replies.
Sort Posts: Previous Next
  •  03-08-2010, 2:28 PM 8086

    Ajutor - ListBox VisualStudio ASP.Net

    Urmatoarea situatie - System.NullReferenceException: Object reference not set to an instance of an object. :
    Visual Studio 2005 ASP.Net urmatorul cod:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    cs.Open()
    sqlfltr = "select * from complet"
    da = New SqlDataAdapter(sqlfltr, cs)
    da.Fill(ds, sqlfltr)
    dv = New DataView(ds.Tables(sqlfltr))
    lstcomplete.DataSource = dv
    lstcomplete.DataValueField = "nume"
    lstcomplete.DataTextField = "nume"
    lstcomplete.DataBind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    txtcomplet.Text = lstcomplete.SelectedItem.Value
    End Sub

    Se populeza cu datele din baza apoi da urmatoarea eroare:
    Server Error in '/test' Application.
    --------------------------------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:
    Line 22:
    Line 23: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Line 24: txtcomplet.Text = lstcomplete.SelectedItem.Value
    Line 25: End Sub
    Line 26:
    Source File: C:\Inetpub\wwwroot\test\Default.aspx.vb Line: 24

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
    _Default.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\test\Default.aspx.vb:24
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +78
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +100
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2863




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

    Multumesc Anticipat ma doare capul de cateva zile si nu-i dau de cap.

    P.S. Incepator in ale programatului
  •  03-08-2010, 2:53 PM 8087 in reply to 8086

    Re: Ajutor - ListBox VisualStudio ASP.Net

    1. Trebuia sa pui if(Not Ispostback) in Page_load , altfel ti se incarca combo-ul de fiecare data

    2. Daca nu ai nimic in lstcomplete , ce te faci ? ( sa zicem ca nu ai nimic in tabela complet)

    if not (lstComplete.SelectedItem is nothing) then
    txtcomplet.Text = lstcomplete.SelectedItem.Value
    else
    ' ce pui acolo ?




    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  03-08-2010, 3:06 PM 8088 in reply to 8087

    Re: Ajutor - ListBox VisualStudio ASP.Net

    OK - multumesc mult (Incepator). Am pus conditia (Not IspostBAck) si functioneaza, insa daca selectez prima linie cu indexul i=0 nu se intampla nimic ca si cum nu as fi selectat nimic.
  •  03-08-2010, 3:39 PM 8089 in reply to 8088

    Re: Ajutor - ListBox VisualStudio ASP.Net

    pai poti pune autopostback la true - ca sa faca postback

    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  03-09-2010, 8:32 AM 8090 in reply to 8089

    Re: Ajutor - ListBox VisualStudio ASP.Net

    Am pus autopostback si aceiasi problema, nu pot selecta primul ITEM, index i=0. Multumesc pentru ajutor, in rest functioneza.
    Daca populez LisBoxul - cu wizardul pus la bataie de VS se intampla acelasi lucru, item i=0 nu il pot selecta. Banuiesc ca este ceva de la mine.
  •  03-09-2010, 11:08 AM 8092 in reply to 8090

    Re: Ajutor - ListBox VisualStudio ASP.Net

    Pai... habar nu am ce intelegi tu prin "nu pot selecta"....

    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  03-09-2010, 12:06 PM 8093 in reply to 8092

    Re: Ajutor - ListBox VisualStudio ASP.Net

    scuze, m-am exprimat gresit

    selectez primul item din lstComplete i=0 si
    cand apelez
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    txtcomplet.Text = lstcomplete.SelectedItem.Value
    End Sub

    rezulta
    txtcomplet.Text nu afiseaza nimic ca si cum nu as fi selectat nimic, daca selectez al doilea sau urmatoarele totul este ok.

  •  03-09-2010, 12:18 PM 8094 in reply to 8093

    Re: Ajutor - ListBox VisualStudio ASP.Net

    ce este in codul html(nu aspx!) la lstcomplete ?

    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  03-09-2010, 12:33 PM 8095 in reply to 8094

    Re: Ajutor - ListBox VisualStudio ASP.Net

    td style="width: 151px" rowspan="3"
    asp:Label ID="lblComplete" runat="server" Text="Lista complete"/asp:Label>
    asp:ListBox ID="lstComplete" runat="server" Height="317px" Width="176px"/asp:ListBox /td
    td style="width: 49px"


    respectivul ListBox este pus intr-o celula a unui tabel daca conteaza asta
  •  03-09-2010, 12:55 PM 8096 in reply to 8095

    Re: Ajutor - ListBox VisualStudio ASP.Net

    tocmai ti-am spus in html, nu in aspx ...
    Ruleaza pagina in IE/FF  , da-i View=> Source si cauta lstComplete

    Ignat Andrei
    http://serviciipeweb.ro/iafblog
  •  03-09-2010, 4:04 PM 8098 in reply to 8096

    Re: Ajutor - ListBox VisualStudio ASP.Net

    multumesc mult pentru ajutor, problema era de la mine. Am pus o conditie (inainte sa pun If NOT ISpostBack) in cazul in care SelectedIndex = 0 sa-mi afiseze un mesaj ca sa pot vedea ce valoare are indexul, dupa ce m-ai ajuta am uitat sa scot acea conditie. Acum totul este OK. Multumesc inca o data
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems