Please Please Please help

I am trying to populate a second dropdownlist from the first.  both dropdownlists are displayed inside the datagrid.  I can populate the first one easily but my onselectedindexchanged event states:

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 195:
Line 196:
Line 197: if lstCPUMan.Selectedvalue = "Dell" then
Line 198: lstCPUMod.items.Add("Optiplex GX110")
Line 199: lstCPUMod.items.Add("Optiplex GX260")

Source File: C:\Inetpub\wwwroot\LocSearch.aspx Line: 197
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
ASP.LocSearch_aspx.lstCPUMan_selectedindexchanged(Object sender, EventArgs e) in C:\Inetpub\wwwroot\LocSearch.aspx:197
System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +108
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +26
System.Web.UI.Page.RaiseChangedEvents() +115
System.Web.UI.Page.ProcessRequestMain() +1081


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
here is the code:

Function CPUSearch(ByVal Location As String, byval strsortfield as string) As System.Data.DataSet
Dim connectionString As String = "server='snake'; user id='sa'; password='<Secret>'; Database='PayPal_Inventory'"& _
""
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [CPU].* FROM [CPU] WHERE ([CPU].[Location] = @Location) Order by " & strsortfield
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlCommand.Parameters.Add("@Location", System.Data.SqlDbType.VarChar).Value = location
Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
dgrdCPU.datasource = dataset
dgrdCPU.databind()
Return dataSet
End Function

Function CPUUpdate(ByVal ID As String, ByVal cPUPPID As String, ByVal cPUMan As String, ByVal cPUMod As String, ByVal cPUSN As String) As Integer
Dim connectionString As String = "server='snake'; user id='sa'; password='v!k!ng57373'; Database='PayPal_Inventory'"& _
""
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "UPDATE [CPU] SET [PayPal_ID]=@CPUPPID, [Manufacturer]=@CPUMan, [Model]=@CPUMod, ["& _
"SN#]=@CPUSN WHERE ([CPU].[ID] = @ID)"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlCommand.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value = ID
sqlCommand.Parameters.Add("@CPUPPID", System.Data.SqlDbType.VarChar).Value = cPUPPID
sqlCommand.Parameters.Add("@CPUMan", System.Data.SqlDbType.VarChar).Value = cPUMan
sqlCommand.Parameters.Add("@CPUMod", System.Data.SqlDbType.VarChar).Value = cPUMod
sqlCommand.Parameters.Add("@CPUSN", System.Data.SqlDbType.VarChar).Value = cPUSN
Dim rowsAffected As Integer = 0
sqlConnection.Open
Try
rowsAffected = sqlCommand.ExecuteNonQuery
Finally
sqlConnection.Close
End Try
Return rowsAffected
End Function
sub dgrdCPU_sort(server as object, e as datagridsortcommandeventargs)
CPUSearch(txtlocation.text, e.sortexpression)
end sub
sub dgrdCPU_Edit(server as object, e as datagridcommandeventargs)
dgrdCPU.edititemindex = ctype(e.item.itemindex, Integer)
dgrdCPU.datasource = CPUsearch(txtLocation.text, "PayPal_ID")
dgrdCPU.databind()
end sub
sub dgrdCPU_Cancel(Server as object, e as datagridcommandeventargs)
dgrdCPU.edititemindex = -1
dgrdCPU.datasource = CPUsearch(txtLocation.text, "PayPal_ID")
dgrdCPU.databind()
end sub
sub dgrdCPU_Update(server as object, e as datagridcommandeventargs)

dim ID as integer = e.item.cells(0).text
dim CPUPPID_Value as textbox = e.item.cells(2).controls(0)
dim CPUMan_Value as string = ctype(e.item.findcontrol("lstCPUMan"), dropdownlist).selecteditem.value

dim CPUMod_Value as string = ctype(e.item.findcontrol("lstCPUMod"), dropdownlist).selecteditem.value
dim CPUSN_Value as textbox = e.item.cells(5).controls(0)
CPUUpdate(ID, CPUPPID_Value.text, CPUMan_Value, CPUMod_Value, CPUSN_Value.text)
dgrdCPU.editItemIndex = -1
dgrdCPU.datasource = CPUSearch(txtLocation.text, "PayPal_ID")
dgrdCPU.databind()
end sub
sub dgrdCPU_itemdatabound(sender as object, e as datagriditemeventargs)
dim itemtype as listitemtype = e.item.itemtype
if(itemtype = listitemtype.edititem) then
dim lstCPUMan as dropdownlist= ctype(e.item.findcontrol("lstCPUMan"), dropdownlist)
dim myrow as datarowview = ctype(e.item.dataitem, datarowview)
dim myrole as string = myrow("Manufacturer").tostring()
lstCPUMan.datatextfield = "Manufacturer"
lstCPUMan.datavaluefield = "Manufacturer"
dgrdCPU.datasource = CPUSearch(txtlocation.text, "PayPal_ID")
dgrdCPU.databind()
lstCPUMan.items.findbytext(myrole).selected = true
end if
end sub
sub lstCPUMan_selectedindexchanged(sender As Object, e As EventArgs)

if lstCPUMan.Selectedvalue = "Dell" then
lstCPUMod.items.Add("Optiplex GX110")
lstCPUMod.items.Add("Optiplex GX260")
lstCPUMod.items.Add("Optiplex GX270")
else if lstCPUMan.Selectedvalue = "Hewlet Packard" then
lstCPUMod.items.Add("Vectra VL400 MT")
lstCPUMod.items.Add("Vectra VL420 MT")
lstCPUMod.items.Add("Brio SA 410")
lstCPUMod.items.add("Xeon X4000")
else if lstCPUMan.Selectedvalue = "IBM" then
lstCPUMod.items.Add("Netvista 8307-25U")
end if
end sub
here is the html:
<asp:DataGrid id="dgrdCPU" runat="server" Width="511px" onupdatecommand="dgrdCPU_Update" AllowSorting="True" BorderStyle="Solid" BorderColor="Navy" BorderWidth="2px" onsortcommand="dgrdCPU_sort" AutoGenerateColumns="False" oneditcommand="dgrdCPU_edit" oncancelcommand="dgrdCPU_cancel" onload="page_Load" autopostback="true">
<HeaderStyle font-underline="True" font-bold="True" forecolor="#000040" borderstyle="Solid" bordercolor="Navy" backcolor="Teal"></HeaderStyle>
<AlternatingItemStyle borderwidth="3px" borderstyle="Solid" bordercolor="Navy" backcolor="#00C0C0"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn DataField="ID" ReadOnly="True" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Location" ReadOnly="True" HeaderText="Location"></asp:BoundColumn>
<asp:BoundColumn DataField="PayPal_ID" SortExpression="PayPal ID" HeaderText="PayPal ID"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="Manufacturer" HeaderText="Manufacturer">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Manufacturer") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id="lstCPUMan" onselectedindexchanged="lstCPUMan_selectedIndexChanged" autopostback= "true" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Manufacturer") %>'>

<asp:ListItem Value="Dell">Dell</asp:ListItem>
<asp:ListItem Value="Hewlet Packard">Hewlet Packard</asp:ListItem>
<asp:ListItem Value="IBM">IBM</asp:ListItem>
</asp:dropdownlist>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="model" HeaderText="Model">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Model") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id="lstCPUMod" runat="server" ></asp:Dropdownlist>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="SN#" SortExpression="Serial #" HeaderText="Serial #"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
</p>


Jake
0
jakvike
12/3/2003 8:59:16 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
1556 Views

Similar Articles

[PageSpeed] 24

First of all I have to ask you to use the < code></ code> tags to improve readbility of your code in the future. I have done this for you this time. I also suggest you do NOT leave your SQL Server password, which I also removed.

In your lstCPUMan_selectedindexchanged method, try using Findcontrol:

Dim myMAN As DropdownList = Ctype(Page.FindControl("lstCPUMan"),DropDownList)
Dim myMOD As DropdownList = Ctype(Page.FindControl("lstCPUMod"),DropDownList)
If myMAN.Selectedvalue = "Dell" then
myMOD.items.Add("Optiplex GX110")
myMOD.items.Add("Optiplex GX260")
....

Regards

Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
0
adec
12/3/2003 9:05:00 AM
No dice,  after selecting MyMan the debugger shows the value as nothing.
Jake
0
jakvike
12/3/2003 10:46:59 PM
I found the code to do it, thanks to 4guysfromrolla  here is the code


Dim CPUMAN As dropdownlist = sender
dim dgrdCPU as datagriditem = CPUMan.parent.parent
Dim CPUMoD As dropdownlist = dgrdCPU.findcontrol("lstCPUMod")
dim CPUManID as string = CPUMan.selecteditem.value
CPUMod.items.clear()
if CPUManID = "Dell" then
CPUMod.items.Add("Optiplex GX110")
CPUMod.items.Add("Optiplex GX260")
CPUMod.items.Add("Optiplex GX270")
CPUMod.items.add("Precision 650")
else if CPUManID = "Hewlet Packard" then
CPUMod.items.Add("Vectra VL400 MT")
CPUMod.items.Add("Vectra VL420 MT")
CPUMod.items.Add("Brio SA 410")
CPUMod.items.add("Xeon X4000")
else if CPUManID = "IBM" then
CPUmod.items.Add("Netvista 8307-25U")
end if
Me.SetFocus(Me.dgrdCPU)

Jake
0
jakvike
12/5/2003 5:07:15 AM
Reply:

Similar Artilces:

Please! Please! Please! Please! Help
I am very new to the Linux/Oracle/Perl world coming from a many many years of a Windows environment. I have self learned everything I know about this new environment. So far I have successfully installed Redhat 9 in an Intel box and have gotten Oracle 9I running correctly. I can run scripts via sqlplus, sqlldr etc. Perl (I think ver. 5.8.0) is running on the box and I can create and run scripts that do other processes but I have had no success in getting Perl to connect to the Oracle database to generate some reports. With my experience using MS-SQL there is no major issues w...

PLEASE PLEASE PLEASE
Name: Nick Crain Email: n.crain_at_rogers.com Product: Firefox Summary: PLEASE PLEASE PLEASE Comments: Can you please include a rss feed indicator thing like IE 7 has. You know where every time you visit a page that has an rss feed available it beeps and then you can subscribe to it? That is such a handy feature. It's just too bad it's on a damn microsux product. please put it in firefox. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Nick Crain wrote: > Name: Nick Crain > Email: n.crain_at_r...

Please Please Please
I have only been asking for 4 years but PLEASE include a setting at the accounts level that sets the default compose to plain text if the account of type NEWS. Its a PITA to have to recall or remember to change my compose to plain text manually! Andre, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been resolved? If not, you might try one of the following options: - Do a search of our knowledgebase at http://support.novell.com/search/kb_index.jsp - Check a...

please please please
Name: Product: Firefox Summary: please please please Comments: could you please resolve this crashing. the browsers crashes so often... I'm watching streaming video and it crashes in the middle of it... which costs me. I don't want to exceed me bandwith with friggin rogers. they're a pain. Browser Details: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you mus...

Please please please
Folks, Please can we stop the petty bickering about banning or not banning............... The points have been made and in my opinion this is not the place to carry on with it. Once again - PLEASE! Regards Ian _____________________________________ Ian Sargent Education & Training Consulting Services Ltd Tel/Fax: 01344 644579 Mobile: 07970 847197 email: ians@etcs.co.uk www: http://www.etcs.co.uk _____________________________________ "Ian Sargent" <ians@nospam_etcs.co.uk> wrote in news:af7d6c$2da6$1 @news.grc.com: > Please can we st...

Please, please, please ....
Name: Dean Talboys Email: deanatlouistalboysdotcom Product: Firefox Summary: Please, please, please .... Comments: Could you include a button on Firefox to register the currently viewed site as Firefox "Unfriendly"? I'm a developer of sophisticated Internet applications (check out http://www.psychl.com/ONE/cyclex.asp to see how much abuse a browser can take) and I always spend time to ensure my sites are IE and Firefox compatible. But I'm really frustrated at the number of sites that aren't Firefox compatible. You know, you get to the last screen of ...

Please help, please, please
This is driving me crazy, I cannot find what is wrong with this thing. I have a custom module and after post back none of the following are processed : user, login, visibility, title, solpartmenu. None of it gets processed. Please help meYou died at the very end of your life Are you saying a skin, or a custom module. With custom modules you should not be dealing with tokens, I don't think they have anything to do with it. What module are you working with? No I am not using tokens, container skin is Classic skin that comes with DNN. I am talking about custom module. It has a text box a...

Please Please Please HELP!!!
I have posted this many times to no avail. I managed to publish the site somwhere despite being an intranet. I have published the site just in case I was not clear in explaining the prblem that I was having. Go to http://www.undg.ks.undp.org/test/login.aspx and login with userid: test password: test Click on 'search for cases' and then click on the search button (the dates are inserted automatically). Click on the paging and try to go to page 12,13,14,15 - any page really above page 11. Can you see what is happening? Below is the code that I am using. Please tell me wha...

Please Please Please help me out...
hello, our netware 6.0 file server can'nt connect the internet, we have a proxyserver with netware 6.0 and BM 3.8. can somebody please help me out i'm a newbie. hello, our netware 6.0 file server can'nt connect the internet, we have a proxyserver with netware 6.0 and BM 3.8. can somebody please help me out i'm a newbie. the file server ip is 192.20.71.1 the proxy ip is 192.20.71.252 akula_26@hotmail.com wrote: > our netware 6.0 file server can'nt connect the internet, we have a > proxyserver with netware 6.0 and BM 3.8. can somebody please hel...

LDAP Request Help
My head is about to fly off my neck and shoot through the ceiling! Ive been trying to make the following code work for weeks, and I cannot figure it out. The code is located at this website: http://v5.beta.docutek.com/eres/custom/fresnoLDAP.aspx. Everytime I try to run this sub I get the following error: "Unknown error (0x80005000) 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.Runtime.InteropServic...

Please, Please
Name: Ernesto Rodriguez Email: aspacsaathotmaildotcom Product: Thunderbird Summary: Please, Please Comments: Hey Guys, If you really want us to reclaim our inbox, please make Thunderbird work with exchange. Browser Details: Opera/9.20 (X11; Linux i686; U; en) ...

PLEASE TEACH ME HOW TO SEND EMAIL...PLEASE PLEASE PLEASE!!
Hi,I am new to this forum and hope it will help me reach out for my target. well, my task is to create a web page with followign description. please help me out the email part. well, it is a request form page where, when one fills up the request adn clicks the submit request button, and information should go automatically to the authorizer, saying that so and so request has been made and the detail of the post can also be viewed in so and so page (folow the link to view detail) and when the person opens the page, there is a button called "grant the request". when only that button i...

Please, please help.
My web page would not show, so I wrote and uploaded a small config file. The index.aspx file will show now. Now I have a problem that is horrible. When My website is displayed, it is really, really slow to load. All images are displayed one after another it appears. For example, my toolbar buttons will display, coming in about once every second. Then other images succesively come in slow. It looks so bad. Imagine 1996 with a slow pc accesing the web. Just like that. What can I do? Is there a way to cache everything in a page before it is actually displayed to the screen. I am rea...

Please, Please Help!
I have been trying to figure this out for weeks now and I dont know what is going on. I am trying to insert a row into a database and for some reason it gives me this error. I really need help on this, I have been trying to figure this out for SO long and I can't find anything anywhere.     Unable to open the physical file "C:\ASP.NET\App_Data\dbInfo.mdf". Operating system error 5: "5(Access is denied.)".An attempt to attach an auto-named database for file C:\ASP.NET\App_Data\dbInfo.mdf failed. A database with the same name exists, or specified file canno...

Web resources about - Please Please Please help - asp.net.web-forms

Obama’s Speech on Terrorist Threat Is a Plea for Patience and National Unity
The president used his address Sunday night to make the case that his administration was ahead of the problem the Islamic State poses, and that ...

Kendrick Lamar And Taylor Swift Killing It With Grammy Nominations
Both Kendrick Lamar and Taylor Swift are killing it with Grammy nominations. Lamar is leading the way with a total of 11 nominations, but Swift ...

Cop Not Charged in 2nd Chicago Police Shooting
Ronald Johnson, 25, was shot dead by an officer in October 2014.

Prosecutor Says No Charges for 2nd Chicago Police Officer Who Fatally Shot a Black Man in 2014
Prosecutor says no charges for 2nd Chicago police officer who fatally shot a black man in 2014

67 Photos From Inside Disney’s Secret Star Wars Press Event
About two weeks ago, we got an email inviting us to an event. All it said: it was about Star Wars, and it would take place in Los Angeles. Where ...

‘Spotlight’ Named Best Film by Washington, D.C. Area Film Critics Association
“Mad Max: Fury Road” and “Spotlight” led the Washington, D.C. Area Film Critics Association Awards, with the latter nabbing the top prize. “Spotlight” ...

Jimmy Carter's remission illustrates power of new cancer drugs
USA TODAY Jimmy Carter's remission illustrates power of new cancer drugs USA TODAY Former President Jimmy Carter 's successful treatment for ...

Venezuela's opposition trounces Socialist party founded by Hugo Chavez
The Democratic Unity coalition won 99 seats to the Socialist party's 46 in the 167-national National Assembly, the election board said, with ...

Hillary Clinton Urges Silicon Valley to 'Disrupt' ISIS
David E. Sanger / New York Times : Hillary Clinton Urges Silicon Valley to ‘Disrupt’ ISIS — WASHINGTON — Hillary Clinton said on Sunday that ...

‘Final Fantasy VII Remake’ To Be A Multi-Part Series, Square Enix Clarifies What That Means
Yesterday, the internet was abuzz with news that Final Fantasy VII REMAKE would be an episodic release . Quickly fans began to predict the worst ...

Resources last updated: 12/7/2015 6:46:44 PM