Partial Class box
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If Page.IsPostBack = True Then
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
If Convert.ToInt32(cost.Text) > Convert.ToInt32(pay.Text) Then
Dim but As Button = FormView1.FindControl("button1")
Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
End Sub
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
Session("cost") = cost If Convert.ToInt32(cost.Text) < Convert.ToInt32(pay.Text) Then
label.Text = "your money is overloaded"
Else
If (HiddenField1.Value.ToLower() = "true") Then
Response.Write("your money is little")
Else
Response.Write("your money is small")
End If
End If
End Sub
End Class
the code in top is error textbox(pay)...
i want:
if i run page,it will display button. after click the button, it display formview. in formview is containning :
no order label(id:no_orderlabel)
cost label(id:costlabel)
pay textbox(id:pay)
click me(buton)
that pay(textbox) is manually i add it...
because in button2_click event use the code Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
so the first i click button, it will display data in formview with condition no order=1, like that:
no order 1
cost 10000
pay textbox(id:pay)
click me(buton)
so, i can input value to textbox. if i input 20000, it will display label "your money is overloaded"
if i input 200, it will display msgbox that have yes/no statement..
as long as i try and try again about code in top and change it, it can work but have problem like:
-can display msgbox, but in the second click.. the msgbox is late to display..
-can display msgbox at first click, but if i input 20000, it display msgbox and label. it should only display label..
so how to solve that problem?
i have try 30 hours for this...
the code in the top almost work,it's only error "format string....." at line textbox(pay). because i am using page.ispostback=true, the data in databound is firing the first before button1_click event fired. so it's to late to input value to textbox(pay),
so value in pay is empty, and it display error"format string...." i must use page.ispostback=true, so the msgbox is not late to show...
how should i do?
is there need change javascript or other event?
pls... thx...
hardy
Member
350 Points
477 Posts
javascript and label is firing in the formview with condition..
Jan 24, 2008 02:40 AM|LINK
yes, i have master page with a content placeholder, but because my real project is have many code, so i make in testpage that no have masterpage.
sory, because my real project use formview, so in the testpage, i change the gridview to formview....
ok, i will explain detail...
my testpage is name box.aspx
my sql datasource is take from database is name orderdetail like this:
no order cost
1 10000
2 5000
this is box.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="box.aspx.vb" Inherits="box" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javacsript" type="text/javascript">
function DisplayConfirmation()
{
if(confirm('Are u sure'))
{
document.getElementById('<%=HiddenField1.ClientID%>').value = "true"
}
else
{
document.getElementById("<%=HiddenField1.ClientID%>").value = 'false'
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Button" /><br />
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:GAMESConnectionString %>"
SelectCommand="SELECT [no_order], [cost] FROM [orderdetail] WHERE ([no_order] = @no_order)">
<SelectParameters>
<asp:Parameter Name="no_order" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource4">
<ItemTemplate>
no_order:
<asp:Label ID="no_orderLabel" runat="server" Text='<%# Bind("no_order") %>'></asp:Label>
<br />
cost:
<asp:Label ID="costLabel" runat="server" Text='<%# Bind("cost") %>' ></asp:Label>
pay :<asp:TextBox ID="pay" runat="server"></asp:TextBox><br />
<asp:Button ID="button1" runat="server" Text="click me" CommandName="clicke" OnClick="button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>
this is my box.aspx.vb
Partial Class box
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If Page.IsPostBack = True Then
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
If Convert.ToInt32(cost.Text) > Convert.ToInt32(pay.Text) Then
Dim but As Button = FormView1.FindControl("button1")
but.Attributes.Add("onclick", "DisplayConfirmation()")
End If
End If
End Sub
Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
End Sub
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
Session("cost") = cost
If Convert.ToInt32(cost.Text) < Convert.ToInt32(pay.Text) Then
label.Text = "your money is overloaded"
Else
If (HiddenField1.Value.ToLower() = "true") Then
Response.Write("your money is little")
Else
Response.Write("your money is small")
End If
End If
End Sub
End Class
the code in top is error textbox(pay)...
i want:
if i run page,it will display button. after click the button, it display formview. in formview is containning :
no order label(id:no_orderlabel)
cost label(id:costlabel)
pay textbox(id:pay)
click me(buton)
that pay(textbox) is manually i add it...
because in button2_click event use the code Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
so the first i click button, it will display data in formview with condition no order=1, like that:
no order 1
cost 10000
pay textbox(id:pay)
click me(buton)
so, i can input value to textbox. if i input 20000, it will display label "your money is overloaded"
if i input 200, it will display msgbox that have yes/no statement..
as long as i try and try again about code in top and change it, it can work but have problem like:
-can display msgbox, but in the second click.. the msgbox is late to display..
-can display msgbox at first click, but if i input 20000, it display msgbox and label. it should only display label..
so how to solve that problem?
i have try 30 hours for this...
the code in the top almost work,it's only error "format string....." at line textbox(pay). because i am using page.ispostback=true, the data in databound is firing the first before button1_click event fired. so it's to late to input value to textbox(pay), so value in pay is empty, and it display error"format string...." i must use page.ispostback=true, so the msgbox is not late to show...
how should i do?
is there need change javascript or other event?
pls... thx...