Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Saturday, March 24, 2012

Please Help - Where is the mistake in my code

Hi all

When I run this app, select the checkbox and press the calculate button i get the following error:

Server Error in '/' 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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] nihe.SimpleRent.calculate(Object source, EventArgs e) +173 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292

My code is as follows, does anyone know what i have done wrong, any help/advice would be very much appreciated.

<%@dotnet.itags.org. Page Language="VB" Debug="true"Inherits="nihe.SimpleRent" ContentType="text/html" ResponseEncoding="iso-8859-1" %><html><body> <form runat="server"> Bathroom with W/C: <asp:CheckBox id="bath_wc" runat="server"></asp:CheckBox> <p> <asp:button id="calcbutton" onclick="calculate" runat="server" text="calculate"></asp:button> </p> </form></body></html>
' SimpleRent.vb'Imports SystemImports System.WebImports System.Web.UIImports System.Web.UI.WebControlsNamespace nihePublic Class SimpleRent : inherits page protected withevents bath_wcAs system.web.ui.webcontrols.checkbox protected withevents row_bwcAs system.web.ui.webcontrols.TableRowPublic sub calculate(source asObject, e as EventArgs) if bath_wc.checked then bath_wc.text ="+3" Context.Items.Add("bath_wc", bath_wc.text) row_bwc.Visible = bath_wc.checked end ifserver.transfer("SimpleResult.aspx")End SubEnd ClassEnd Namespace
<%@dotnet.itags.org. Page Language="vb" %><script runat="server">Sub Page_Load(Source asObject, E as EventArgs) cell_bwc.text ="Bathroom With WC" value_bwc.text = Context.Items("bath_wc")End Sub</script><html><body><form> <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table></form></body></html>

Where did you get this code from?

<html>
<body>
<form>
<asp:Table runat="server">
<asp:TableRow id="row_bwc">
<asp:TableCell id="cell_bwc"></asp:TableCell>
<asp:TableCell id ="value_bwc"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>

I see 2 html parts in the code you posted.

Thanks


Because your Calculate method is encapsulated in a page that does not exist. Therefore, "row_bwc" does not exist.

For some reason, it seems you have attempted to create an inheritable base page that is actually a "real" page?


Sorry should have been more specific.

The code show is actaully three seperate pages

page one, codebehind for page one and results page.

Hope this clarifies things

Sorry

Kevin


The last line of your Calculate method attempts to executerow_bwc.Visible = bath_wc.checked. No instance of row_bc has been created. Therefore,row_bc is a null reference.

Remember, there's no row_bc on page one. It's only on the results page.


Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin


It seems you mix 2 web pages.You have 2 webpages A and B,you can only access controls of A in codebehind of A.

"So where do i need to reference row_bwc and how do it do it?"

You have 2 choice .

1: Combine page one and result page to a single page.That means add:

 <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table>

to page one and don't forget add code in pageload to page one. Then use YourControl.visible to display or hide controls.

2: pass parameter (like row_bwc.Visible,etc )to SimpleResult.aspx then do the action within SimpleResult.aspx.


Kipster:

Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin

You need to pass the value to set the visibility of row_bwc to the SimpleResult page. You could do this in one of the many ways that you would normally pass values between pages -- like in a QueryString, or drop the Server.Transfer and do a crosspost instead. Let me know if you need an example.

Please Help Datagrid Columns

I have a table called Computers with 8 colunms.

I have a select query that list out the Computer brand and the price.
what I want is that when I click on the computer brand then the respective information about this brand will be display in the same page or open a new page. I am using a datagrid, how do I make this work? or should I use other component like table.
Please helpIf you have unique Identifier for the Computerband table use it to create a hyperlink column in the datagrid. then pass the id as querystring. During the postback event read the Id get the details of the brand form from the id and then you can display that in formation in a panel below this grid.

Note;
1. AutoGenerateColumns property must be set to False
2. Manually Create DataGrid columns including the hyperlink column

Ex:


<asp:DataGrid id="dg1" AutoGenerateColumns="False" runat="server">
<asp:HyperLinkColumn Headertext="Brand Id" DataTextField="BrandId" DataNavigationUrlField="BrandId" DataNavigationUrlFormatString="ComputerBrands.aspx?brandId={0}" />
<asp:BoundColumn DataField="ComputerBrandName" HeaderText="Brand Name"/>
<!-- .... add other columns -->
</asp:DataGrid

Thanks
Thank you Jay.

I still have som problem, I create a procedure that reads
Create Proc GetComputerID

@.ComputerID int

as
Select Computer,Price,CPU from Computers
Where ComputerID = @.ComputerID

I do not know where to pass the parameter in the grid, and I could not type computerID={0}
vb.net would not even allow me to run the application
I removed the where claus from my statement. But when I click on the hyperlink, nothing happens.
Here is the ASP code:
<asp:HyperLinkColumn Text="Computer" Target="_self" DataNavigateUrlField="ComputerID" DataNavigateUrlFormatString="UsedComputer.aspx?ComputerId={0}"
DataTextField="Computer" HeaderText="Computer" NavigateUrl="Computer"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="ComputerID" HeaderText="ComputerID"></asp:BoundColumn>
</Columns>

Wednesday, March 21, 2012

please help me on multiple update recordset

when i select 2 records to update from checkbox, it only updated 1 record. can anyone help me?

code
====

<%
if request("deleted")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause from Users where id IN ("&request("deleted")&")"
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="1"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script
=======================================================Instead of if ... then go for

while not rs.eof
rs("pause")="1"
rs.update
rs.movenext
wend

:))
Devendra.
Thanks cdnaik
I't works.
:)

Friday, March 16, 2012

Please Help Select Statement Issue

I am trying to use a datagrid to display the data when the user enters a number into a textbox.

Below is my code:

Dim theVal As Integer = cInt(major.text , Integer)

' major is the name of the textbox

SELECT * FROM glmaster WHERE glmaster.major = theVal

When I put a number ie. 1000 where theVal is in the select statement, the datagrid displays the correct data. But as soon as I put a variable there I get an error.

Try "SELECT * FROM glmaster WHERE glmaster.major =" + theVal.ToString