Data binding in TextBox after dropdown list indexchanged

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGF2aWQ=?=, Apr 1, 2005.

  1. I have a question in the following. Any one could give me a help?
    Thanks
    David

    The dataset is declared and created at Class level. My source code is here:

    Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
    txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    txtLastName.Text =
    ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")

    When Page_load,
    I use Dropdown list index to set all textboses. Now select another item in
    Dropdown list, I got the following error at Line 323:

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

    Source Error:
    Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    Line 323: txtLastName.Text =
    ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")

    Line: 323
     
    =?Utf-8?B?ZGF2aWQ=?=, Apr 1, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?ZGF2aWQ=?=

    Karl Seguin Guest

    txtLastName is null, ds is null or there's no table named "Patients"....we
    can't tell which it is, but one of those is true...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "david" <> wrote in message
    news:...
    > I have a question in the following. Any one could give me a help?
    > Thanks
    > David
    >
    > The dataset is declared and created at Class level. My source code is

    here:
    >
    > Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As

    System.Object,
    > ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
    > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > txtLastName.Text =
    > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    >
    > When Page_load,
    > I use Dropdown list index to set all textboses. Now select another item in
    > Dropdown list, I got the following error at Line 323:
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > Source Error:
    > Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > Line 323: txtLastName.Text =
    > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    >
    > Line: 323
    >
    >
     
    Karl Seguin, Apr 1, 2005
    #2
    1. Advertising

  3. ds is a DataSet.
    ds.Tables(0) should be ds.Tables("Patients")
    "LastName" is the colunm name.
    When Page is first loaded, it OK.
    That ocurs when I select a new item of dropdown list.
    It is supporsed to bind a new set of data display in all other textbox.
    Does it mean the dataset ds has disappeared?

    Thanks

    David



    "Karl Seguin" wrote:

    > txtLastName is null, ds is null or there's no table named "Patients"....we
    > can't tell which it is, but one of those is true...
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "david" <> wrote in message
    > news:...
    > > I have a question in the following. Any one could give me a help?
    > > Thanks
    > > David
    > >
    > > The dataset is declared and created at Class level. My source code is

    > here:
    > >
    > > Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As

    > System.Object,
    > > ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
    > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > txtLastName.Text =
    > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > >
    > > When Page_load,
    > > I use Dropdown list index to set all textboses. Now select another item in
    > > Dropdown list, I got the following error at Line 323:
    > >
    > > Exception Details: System.NullReferenceException: Object reference not set
    > > to an instance of an object.
    > >
    > > Source Error:
    > > Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > Line 323: txtLastName.Text =
    > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > >
    > > Line: 323
    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?ZGF2aWQ=?=, Apr 1, 2005
    #3
  4. =?Utf-8?B?ZGF2aWQ=?=

    Karl Seguin Guest

    ds wont' automatically survive a postback....are you repopulating it on
    postback? Storing it somewhere?

    If you have vs.net 2003, debug and step through the code...see what is
    null...no point in trying to solve all 3 potential problems until we know
    which it is..

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "david" <> wrote in message
    news:...
    > ds is a DataSet.
    > ds.Tables(0) should be ds.Tables("Patients")
    > "LastName" is the colunm name.
    > When Page is first loaded, it OK.
    > That ocurs when I select a new item of dropdown list.
    > It is supporsed to bind a new set of data display in all other textbox.
    > Does it mean the dataset ds has disappeared?
    >
    > Thanks
    >
    > David
    >
    >
    >
    > "Karl Seguin" wrote:
    >
    > > txtLastName is null, ds is null or there's no table named

    "Patients"....we
    > > can't tell which it is, but one of those is true...
    > >
    > > Karl
    > >
    > > --
    > > MY ASP.Net tutorials
    > > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > > annoying)
    > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > > come!)
    > > "david" <> wrote in message
    > > news:...
    > > > I have a question in the following. Any one could give me a help?
    > > > Thanks
    > > > David
    > > >
    > > > The dataset is declared and created at Class level. My source code is

    > > here:
    > > >
    > > > Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As

    > > System.Object,
    > > > ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
    > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > txtLastName.Text =
    > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > >
    > > > When Page_load,
    > > > I use Dropdown list index to set all textboses. Now select another

    item in
    > > > Dropdown list, I got the following error at Line 323:
    > > >
    > > > Exception Details: System.NullReferenceException: Object reference not

    set
    > > > to an instance of an object.
    > > >
    > > > Source Error:
    > > > Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > Line 323: txtLastName.Text =
    > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > >
    > > > Line: 323
    > > >
    > > >

    > >
    > >
    > >
     
    Karl Seguin, Apr 1, 2005
    #4
  5. Thank you very much.
    How to store the dataset as for a postback?
    I have .NET 2003. But I never use the debugging tool.

    David

    "Karl Seguin" wrote:

    > ds wont' automatically survive a postback....are you repopulating it on
    > postback? Storing it somewhere?
    >
    > If you have vs.net 2003, debug and step through the code...see what is
    > null...no point in trying to solve all 3 potential problems until we know
    > which it is..
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "david" <> wrote in message
    > news:...
    > > ds is a DataSet.
    > > ds.Tables(0) should be ds.Tables("Patients")
    > > "LastName" is the colunm name.
    > > When Page is first loaded, it OK.
    > > That ocurs when I select a new item of dropdown list.
    > > It is supporsed to bind a new set of data display in all other textbox.
    > > Does it mean the dataset ds has disappeared?
    > >
    > > Thanks
    > >
    > > David
    > >
    > >
    > >
    > > "Karl Seguin" wrote:
    > >
    > > > txtLastName is null, ds is null or there's no table named

    > "Patients"....we
    > > > can't tell which it is, but one of those is true...
    > > >
    > > > Karl
    > > >
    > > > --
    > > > MY ASP.Net tutorials
    > > > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > > > annoying)
    > > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > > > come!)
    > > > "david" <> wrote in message
    > > > news:...
    > > > > I have a question in the following. Any one could give me a help?
    > > > > Thanks
    > > > > David
    > > > >
    > > > > The dataset is declared and created at Class level. My source code is
    > > > here:
    > > > >
    > > > > Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As
    > > > System.Object,
    > > > > ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
    > > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > txtLastName.Text =
    > > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > > >
    > > > > When Page_load,
    > > > > I use Dropdown list index to set all textboses. Now select another

    > item in
    > > > > Dropdown list, I got the following error at Line 323:
    > > > >
    > > > > Exception Details: System.NullReferenceException: Object reference not

    > set
    > > > > to an instance of an object.
    > > > >
    > > > > Source Error:
    > > > > Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > Line 323: txtLastName.Text =
    > > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > > >
    > > > > Line: 323
    > > > >
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?ZGF2aWQ=?=, Apr 2, 2005
    #5
  6. =?Utf-8?B?ZGF2aWQ=?=

    Karl Seguin Guest

    David, left click on the left-side column of VS.Net, a red dot should
    appear...that's a breakpoint...Alternatively, you can put your cursor on a
    line, goto "Debug" --> "New Breakpoint". Now, hit f5 or "Debug" -->
    "Start" which should build and start up your application, launching
    IE...now you can browse your site as always, but when the code execution
    hits any line with a breakpoint, it'll stop at that line...you can use f10
    and f11to step over/in functions/lines....you can add "watches" to
    values...play with it...you won't regret it...

    You either have to reload the dataset, or store it in the Cache or Session
    or some place...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "david" <> wrote in message
    news:...
    > Thank you very much.
    > How to store the dataset as for a postback?
    > I have .NET 2003. But I never use the debugging tool.
    >
    > David
    >
    > "Karl Seguin" wrote:
    >
    > > ds wont' automatically survive a postback....are you repopulating it on
    > > postback? Storing it somewhere?
    > >
    > > If you have vs.net 2003, debug and step through the code...see what is
    > > null...no point in trying to solve all 3 potential problems until we

    know
    > > which it is..
    > >
    > > Karl
    > >
    > > --
    > > MY ASP.Net tutorials
    > > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > > annoying)
    > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > > come!)
    > > "david" <> wrote in message
    > > news:...
    > > > ds is a DataSet.
    > > > ds.Tables(0) should be ds.Tables("Patients")
    > > > "LastName" is the colunm name.
    > > > When Page is first loaded, it OK.
    > > > That ocurs when I select a new item of dropdown list.
    > > > It is supporsed to bind a new set of data display in all other

    textbox.
    > > > Does it mean the dataset ds has disappeared?
    > > >
    > > > Thanks
    > > >
    > > > David
    > > >
    > > >
    > > >
    > > > "Karl Seguin" wrote:
    > > >
    > > > > txtLastName is null, ds is null or there's no table named

    > > "Patients"....we
    > > > > can't tell which it is, but one of those is true...
    > > > >
    > > > > Karl
    > > > >
    > > > > --
    > > > > MY ASP.Net tutorials
    > > > > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > > > > annoying)
    > > > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more

    to
    > > > > come!)
    > > > > "david" <> wrote in message
    > > > > news:...
    > > > > > I have a question in the following. Any one could give me a help?
    > > > > > Thanks
    > > > > > David
    > > > > >
    > > > > > The dataset is declared and created at Class level. My source code

    is
    > > > > here:
    > > > > >
    > > > > > Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As
    > > > > System.Object,
    > > > > > ByVal e As System.EventArgs) Handles

    lstPatientID.SelectedIndexChanged
    > > > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > > txtDebug.Text &= lstPatientID.SelectedIndex.ToString
    > > > > > txtLastName.Text =
    > > > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > > > >
    > > > > > When Page_load,
    > > > > > I use Dropdown list index to set all textboses. Now select another

    > > item in
    > > > > > Dropdown list, I got the following error at Line 323:
    > > > > >
    > > > > > Exception Details: System.NullReferenceException: Object reference

    not
    > > set
    > > > > > to an instance of an object.
    > > > > >
    > > > > > Source Error:
    > > > > > Line 321: txtDebug.Text &=

    lstPatientID.SelectedIndex.ToString
    > > > > > Line 322: txtDebug.Text &=

    lstPatientID.SelectedIndex.ToString
    > > > > > Line 323: txtLastName.Text =
    > > > > > ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")
    > > > > >
    > > > > > Line: 323
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >
     
    Karl Seguin, Apr 4, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Binod Nair

    Dropdown List data binding

    Binod Nair, Jan 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    698
    Hermit Dave
    Jan 16, 2004
  2. Replies:
    2
    Views:
    25,035
    Fraggle
    Sep 14, 2004
  3. mosscliffe

    DropDownList - IndexChanged

    mosscliffe, Jun 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,664
    mosscliffe
    Jun 19, 2006
  4. Mike Milian
    Replies:
    0
    Views:
    339
    Mike Milian
    Apr 14, 2008
  5. Jim Mitchell

    HELP - Fill Datagrid2 from indexchanged in Datagrid1

    Jim Mitchell, Aug 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    135
    Jim Mitchell
    Aug 17, 2003
Loading...

Share This Page