I need to a form for invoicing,
Please help me to have some Idea how to insert all the data at once into invoice table.
I am using text box to get all details for items .
here is the code for get details of items from table.
enter code here<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))%>
<tr>
<td><input name="dipatchid" type="text" id="dipatchid" value="<%=(Recordset1.Fields.Item("dispatchid").Value)%>" size="5" /></td>
<td><input name="dispatchdate" type="text" id="dispatchdate" value="<%=(Recordset1.Fields.Item("dis_date").Value)%>" /></td>
<td><input type="hidden" name="custid_" id="custid_" />
<input name="From_" type="text" id="From_" value="<%=(Recordset1.Fields.Item("from_").Value)%>" /></td>
<td><input name="to_" type="text" id="to_" value="<%=(Recordset1.Fields.Item("To_").Value)%>" /></td>
<td><input name="hrs" type="text" id="hrs" value="<%=(Recordset1.Fields.Item("total_hrs").Value)%>" size="5" /></td>
<td><input name="rate_" type="text" id="rate_" size="8" /></td>
<td><input name="totalamt" type="text" id="totalamt" size="10" /></td>
<td><img src="imgs/error_icon.png" width="16" height="16" alt="Remove" /></td> </tr>
<% Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 Recordset1.MoveNext() Wend %>
To accomplish this, you will need to keep track of two things:
the number of rows that are going to be inserted
the data of each row
Tricks to do this, is simple. While you display your data, you increment a variable with the number of loops.
<%
iNumberOfRecords = 0
Do Until Recordset1.EOF
%>
<tr>
<td>
<input name="dipatchid" type="text" id="..." value="<%=Recordset1("dispatchid")%>" />
</td>
...
</tr>
<%
iNumberOfRecords = iNumberOfRecords + 1
Recordset1.MoveNext
loop
Recordset1.Close
%>
Before you close your <form> tag, you put that in a hidden field.
<input type="hidden" name="iNumberOfRecords" value="<%=iNumberOfRecords%>" />
Next, on the page where you submit to, you loop iNumberOfRecords times to insert all the rows.
<%
for i = 1 to CInt(Request.Form("iNumberOfRecords"))
idOfRecord = GetFormValue("dipatchid", i)
otherField = GetFormValue("otherField", i)
SQL = "INSERT INTO tblInvoices(dispatchid, otherfield) VALUES ( " & idOfRecord & ", " & otherfield & " )"
Connectionobject.Execute(SQL)
next
Function GetFormValue(sFormname, iIndex)
If Request.Form(sFormname).Count >= iIndex And iIndex > 0 Then
GetFormValue = Request.Form(sFormname)(iIndex)
Else
GetFormValue = ""
End If
End Function
%>
The (i) fetches the right Request.Form("...") item for you.
Related
I like to query based on some fields to generate a report: Date range, Department, Student with date range. I have the form to work on searching....
However, I need to calculate totals for each of these fields from a report.
For example: if I search for students and the search results are:
Department Date Range Student Cost
DeptA 1/1/2012-12/31/2012 StuA $100
DeptA 1/1/2012-12/31/2012 StuB $50
DeptA 1/1/2012-12/31/2012 StuC $50
How can I calculate the total of cost automatically online (= $200)?
Thanks.
Here is my code:
<%
Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.open strCon
SelectStmt = "Select * From view_costs Where "
WhereClause = ""
WhereBetweenClause = "BETWEEN"
If Request("qryDepartment") <> "All Departments" Then
qryDepartment = replace(request("qryDepartment"),"'","''")
WhereClause = WhereClause & "Department = '" & qryDepartment & "' AND "
End If
If Request("qryStudents") <> "All Students" Then
WhereClause = WhereClause & "Name = '" & Request("qryStudents") & "' AND "
End If
sStartDate = Request("StartDate")
sEndDate = Request("EndDate")
If IsDate(sStartDate) And IsDate(sEndDate) Then
WhereClause = WhereClause & "(StartDate >= '" & sStartDate & "' AND EndDate <= '" & sEndDate & "') "
End If
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.open strCon
pstart = trim(request.form("pstart"))
pfinish = trim(request.form("pfinish"))
Set getDepartment = Server.CreateObject("ADODB.Recordset")
getDepartment.Open "Select Department from view_costs order by Department;",adoCon
Set getname = Server.CreateObject("ADODB.Recordset")
getname.Open "Select Name from view_costs order by Name;",adoCon
%>
<html>
<head>
<title>The Resport</title>
</head>
<body>
<table width="770" align="center">
<tr>
<td colspan="4" class="n"><span id="h3">Search Menu</span></td>
</tr>
<form method=Department action="Search.asp" name="Search">
<tr>
<td>
<% if not getDepartment.eof then %>
<select name="qryDepartment" size="1" title="Select a Department Name" style="width:200;background-color=#F5D0A9;">
<option selected>All Departments</option>
<% do until getDepartment.eof %>
<option><%= getDepartment("Department") %></option>
<% getDepartment.MoveNext
loop %>
</select>
<% end if %>
</td>
<td>
<% if not getname.eof then %>
<select name="qryStudents" size="1" title="Select a Student Name" style="width:200;background-color=#F5D0A9;">
<option selected>All Students</option>
<% do until getname.eof %>
<option><%= getname("Name") %></option>
<% getname.MoveNext
loop %>
</select>
<% end if %>
</td>
<%
%>
<td><span id="b"> Start:</span> <input name="StartDate" type="text" size="15" maxlength="12" value="<%=sStartDate%>">
<img src="calendar.gif" alt="calendar"></td>
<td><span id="b"> End:</span> <input name="EndDate" type="text" size="15" maxlength="12" value="<%=sEndDate%>">
<img src="calendar.gif" alt="calendar"></td>
</tr>
<tr class="search-bg">
<td colspan="6">
<input type="button" name="Submit" value="Search" onClick="if (isDate()) document.Search.submit();">
</tr></table>
<% If oRs.RecordCount = 0 Then %>
<p></p>
<% Else %>
<table width="960" align="center">
<form method="Department">
<tr bgcolor="#FE9A2E" height="25">
<td class="a"> Department Name</td>
<td class="a"> Student</td>
<td class="a"> Start</td>
<td class="a"> End</td>
<td class="a"> Cost</td>
</tr>
<tr>
<td><%=oRs("Department")%> </td>
<td><%=oRs("Name")%> </td>
<td><%=FormatDateTime(Month(oRs("StartDate")) & "/" & Day(oRs("StartDate")) & "/" & Year(oRs("StartDate")))%> </td>
<td><%=FormatDateTime(Month(oRs("EndDate")) & "/" & Day(oRs("EndDate")) & "/" & Year(oRs("EndDate")))%> </td>
<td <%=sRowStyle%>>$<%=oRs("Cost")%> </td>
</tr>
<% oRs.MoveNext %>
<% WEND %>
</table>
</td>
</tr>
</table>
<% oRs.close
set oRs = nothing
set adoCon = nothing
%>
Why not specify the fields in your SQL (instead of "SELECT * ..."), then add up the values via variables in the loop and output them in a new table row after the loop?
Or you could use SQLs SUM() function to query those values.
I made a table with input text fields with ids of
<td> <INPUT id="txtName1" type="text" runat="server" /> </td>
<td> <INPUT id="txtDescription1" type="text" runat="server" /> </td>
<td> <INPUT id="txtColNum1" type="text" runat="server" /> </td>
<td> <INPUT id="txtColW1" type="text" runat="server" /> </td>
<td> <INPUT id="txtType1" type="text" runat="server" /> </td>
<td> <INPUT id="txtFormula1" type="text" runat="server" /> </td>
<td> <INPUT id="txtCost1" type="text" runat="server" /> </td>
<td> <INPUT id="txtCostFormula1" type="text" runat="server" /> </td>
<td> <INPUT id="txtPullDown1" type="text" runat="server" /> </td>
<td> <INPUT id="chkLock1" type="checkbox" runat="server" /> </td>
<td> <INPUT id="chkHideQ1" type="checkbox" runat="server" /> </td>
<td> <INPUT id="chkHideW1" type="checkbox" runat="server" /> </td>
and have a javascript to add rows dynamically, incrementing the digit of the id such as
txtName2, txtDescription2, txtColNum2 and so on...
Moreover, I'm saving the data to SQL using vb.net with the code below
Protected Sub btnSaveTemplate_Click(sender As Object, e As EventArgs) Handles btnSaveTemplate.Click
SqlCMData.InsertParameters("categoryName").DefaultValue = txtCategory1.Value
SqlCMData.InsertParameters("productName").DefaultValue = txtName1.Value
SqlCMData.InsertParameters("productDescription").DefaultValue = txtDescription1.Value
SqlCMData.InsertParameters("colNum").DefaultValue = txtColNum1.Value
SqlCMData.InsertParameters("colW").DefaultValue = txtColW1.Value
SqlCMData.InsertParameters("type").DefaultValue = txtType1.Value
SqlCMData.InsertParameters("formula").DefaultValue = txtFormula1.Value
SqlCMData.InsertParameters("cost").DefaultValue = txtCost1.Value
SqlCMData.InsertParameters("costFormula").DefaultValue = txtCostFormula1.Value
SqlCMData.InsertParameters("pullDown").DefaultValue = txtPullDown1.Value
SqlCMData.InsertParameters("lock").DefaultValue = chkLock1.Checked
SqlCMData.InsertParameters("hideQ").DefaultValue = chkHideQ1.Checked
SqlCMData.InsertParameters("hideW").DefaultValue = chkHideW1.Checked
SqlCMData.Insert()
End Sub
My problem is, how can I have a for loop get all the values including the other rows with the id's digit have been incremented such as txtCategory*2*?
Lets say the highest number you get to is 10, you could just have a loop.
Here's and example in quasi-code.
for (i = 1; i < 10; i++)
{
INSERT txtCategory + i;
INSERT txtName + i;
INSERT txtDescription + i;
.
.
.
.
.
.
INSERT chkHideW + i;
}
Obviously the INSERT is just an abbreviation for inserting it to a MySQL table. This should allow you to insert all the elements i times, i being the highest numbered suffix you reached. I can't promise this will work but I hope it helps, at least with the logic behind it.
so I have a slight issue with doing 2 things on a web page. I'm using a to upload a file to my web server, at the same time I have other used to get data from the user (first name, last name ect) The form is runat=server, the button that is supposed to upload the file (after some preliminary checking that the file is ok, and that the forms fields are filled out properly) is also runat server, with a onserver click.
The main issue is that, when I give the form a "get" method, I can get the desired result of having all my data in the url where I want it, but then I can't upload a file. While if I remove that tag, I can upload a file, but then I get no data in my url.
(Relevant code)
<script language="VB" runat="server">
Dim str As String
Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs)
'Dim submitFunction As String = "<script type='text/javascript'> function submitform() { document.myform.submit();}" & "</" & "script>"
Session("firstTime") = 4
Session("errCheck") = 1
If InputF.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If
If Not (InputF.PostedFile Is Nothing) Then
Try
If Session("firstTime") <> 1 Then
If Request.QueryString("fName") = "" Then
str += "Please Enter your first name <br/>"
Session("errCheck") += 1
End If
If Request.QueryString("lName") = "" Then
str += "Please Enter your last name <br />"
Session("errCheck") += 1
End If
If Request.QueryString("addr1") = "" Then
str += "Please Enter your address <br />"
Session("errCheck") += 1
End If
If Request.QueryString("city") = "" Then
str += "Please Enter a city name <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("prov")) <> 2 Then
str += "Please Enter a 2 character province <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("pCode")) <> 6 Then
str += "Please Enter a valid postal code <br />"
Session("errCheck") += 1
End If
If Request.QueryString("hPhone") = "" Then
str += "Please Enter your home phone <br />"
Session("errCheck") += 1
ElseIf Len(Request.QueryString("hPhone")) <> 10 Then
str += "Please enter a 10 digit number for your home phone <br />"
Session("errCheck") += 1
End If
End If
If Session("errCheck") = 1 Then
InputF.PostedFile.SaveAs(("FILE PATH TO MY SERVER" & Request.QueryString("compName") & " - " & Request.QueryString("fName") & ", " & Request.QueryString("lName") & InputF.Value))
'Response.Redirect("default.aspx?fName=" & Request.QueryString("fName"))
End If
Catch exc As Exception
str += "Error Saving File"
Span1.InnerHtml = "Error saving file"
Session("errCheck") += 1
End Try
End If
End Sub 'Button1_Click
</script>
<form name="myform" id="myform" method="get" runat="server" enctype="multipart/form-data">
<table>
<h2><% If Session("errCheck") <> 1 Then
Response.Write(Str)
End If%></h2>
<tr>
<td align="right"><label>Resume/Documents</label></td>
<td><input type="file" runat="server" id="InputF" name="InputF" onchange="handleFiles(this.files)" /><input type="button" id="adder" value="add another document" onclick="addInput('dynamicInput');" /></td>
<div id="dynamicInput">
</div>
</tr>
<tr>
<td>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</td>
</tr>
<input type="hidden" id="Hidden13" name="compName" value="<% response.Write(request.QueryString("compName")) %>" />
<input type="hidden" id="posCode" name="posCode" value="<% response.Write(request.QueryString("posCode"))%>" />
<input type="hidden" id="reqNum" name="reqNum" value="<% response.Write(request.QueryString("reqNum")) %>" />
<input type="hidden" id="company" name="company" value="<% response.Write(request.QueryString("company"))%>" />
<input type="hidden" id="division" name="division" value="<% response.Write(request.QueryString("division")) %>" />
<input type="hidden" id="department" name="department" value="<% response.Write(request.QueryString("department"))%>" />
<tr>
<td align="right">First name<span style="color:Red;">*</span>:</td>
<td><input type='text' name='fName' id='fName' size='50' maxlength="50"value="<% Response.Write(Request.QueryString("fName"))%>" /></td>
</tr>
<tr>
<td align="right"><label>Last name </label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='lName' id='lName' size='50' maxlength="50" value="<% response.Write(request.QueryString("lName"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Initial</label>:</td>
<td><input type='text' name='init' id='init' size='2' maxlength="2" value="<% response.Write(request.QueryString("init"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Email</label>:</td>
<td><input type='text' name='email' id='email' size='50' maxlength="50" value="<% response.Write(request.QueryString("email"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 1</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='addr1' id='addr1' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr1"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 2</label>:</td>
<td><input type='text' name='addr2' id='addr2' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr2"))%>"/></td>
</tr>
<tr>
<td align="right"><label>City</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='city' id='city' size='25' maxlength="25" value="<% response.Write(request.QueryString("city"))%>"/></td>
</tr>
<br />
<tr>
<td align="right"><label>Province</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='prov' id='prov' size='2' maxlength="2" value="<% response.Write(request.QueryString("prov"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Country</label>:</td>
<td><input type='text' name='count' id='count' size='25' maxlength="25" value="<% response.Write(request.QueryString("count"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Postal code</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='pCode' id='pCode' size='25' maxlength="25" value="<% response.Write(request.QueryString("pCode"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Home Phone</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='hPhone' id='hPhone' size='15' maxlength="15" value="<% response.Write(request.QueryString("hPhone"))%>"/></td>
<p>Format for phone numbers: Areacode, phone number, no spaces, no dashes ie: 2041231234</P>
</tr>
<tr>
<td align="right"><label>Work Phone</label>:</td>
<td><input type='text' name='wPhone' id='wPhone' size='25' maxlength="25" value="<% response.Write(request.QueryString("wPhone"))%>"/></td>
</tr>
</table>
<input type=button
id="Button1"
value="Submit Application"
OnServerClick="Button1_Click"
runat="server" />
</form>
I was close to getting this myself. On form submit, I do all the validation for the other files, then if all checks out, I submit the form to a different page(with other non-relevant code).
Basically the code I posted is good, I was just missing a few things for when it's submitted
In short:
'if there are no errors with the user feilds
If Session("errCheck") = 1 Then
Try
If Not (System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString()) Is Nothing) Then
Try
InputF.PostedFile.SaveAs(("somepath:\somepath\somepath\somepath\" & Trim(Request.Form("compName")) & " - " & Request.Form("lName") & ", " & Request.Form("fName") & "-" & System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString())))
Catch ex As Exception
Session("errCheck") += 1
str += "Error Saving File" & ex.Message
End Try
If Session("errCheck") = 1 Then
Response.Redirect("final2.aspx?fName=" & Request.Form("fName") & "&lName=" & Request.Form("lName") & "&compName=" & Trim(Request.Form("compName")) &
"&posCode=" & Request.Form("posCode") & "&reqNum=" & Request.Form("reqNum") & "&company=" & Request.Form("company") &
"&division=" & Request.Form("division") & "&department=" & Request.Form("department") & "&init=" & Request.Form("init") &
"&email=" & Request.Form("email") & "&addr1=" & Trim(Request.Form("addr1")) & "&addr2=" & Request.Form("addr2") &
"&city=" & Request.Form("city") & "&prov=" & Request.Form("prov") & "&count=" & Request.Form("count") &
"&pCode=" & Request.Form("pCode") & "&hPhone=" & Request.Form("hPhone") & "&wPhone=" & Request.Form("wPhone"))
End If
Hopefully that makes sense to anyone looking at my question and now my answer.
I was wondering if any one could help me out; I have a table which looks something like the following:
<table id="Table1" border="0">
<tr>
<td><b>1.</b> Question 1</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer1</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer2</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer3</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio1" type="radio" name="Group1" value="Radio1" /><label for="Radio1">Answer4</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr><tr>
<td><b>2.</b> Question 2</td>
</tr><tr>
<td style="border-width:5px;border-style:solid;"></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">yes</label></td>
</tr><tr>
<td align="left" style="width:1000px;"><input id="Radio2" type="radio" name="Group2" value="Radio2" /><label for="Radio2">no</label></td>
</tr><tr>
<td style="height:30px;"></td>
</tr>
</table>
How do I go about looping through each group of radio buttons and getting the text of the selected radio button?
The code displayed above is created dynamically ... in my aspx file I have the following code:
<asp:Table ID="Table1" runat="server">
</asp:Table>
If you want to access the rows in ASP.NET (on the server side), you need to convert the table, rows and the cells to server control (using runat="server") and iterate through the controls in the table.
EDIT : :- If you are adding the rows, cells and radionbuttons following way, all of them will be the server controls (and are runat=server) so that you can access them the way I mentioned above:--
// Create new row and add it to the table.
TableRow tRow = new TableRow();
table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
RadioButton rdb = new RadioButton();
rdb.ID = "rdb_" + cellCtr.ToString();
rdb.Text = "radio button";
rdb.GroupName = "rdbGroup";
tCell.Controls.Add(rdb);
tRow.Cells.Add(tCell);
}
EDIT:-
You can find the controls in each cell.Something like below:-
foreach(TableCell cell in tableRow.Cells)
{
foreach(Control ctrl in cell.Controls)
{
if(ctrl is RadioButton)
{
if(ctrl.Selected)
{
string rdValue=ctrl.Text;
}
}
}
}
Or If you want to iterate on the client side using Javascript, have a look here and you dont have to apply runat="server".
It sounds like you're starting with a barebones <table> in your markup page, and dynamically adding those <input> afterwards.
Consider taking this approach:
Add the runat="server" attribute to your table.
In the code where you're adding those <input> tags, add a new RadioButton control. Use an ID here that you can predict later. Perhaps you can use a RadioButtonList instead, if the choices are logically grouped!
It's unclear if you're manually adding those <tr> and <td> as strings. Consider the option of new TableRow() and new TableCell(). Then add the new RadioButton to the TableCell.Controls collection with tc.Controls.Add(myNewRadioButton);
In your postback code, simply refer to your RadioButton controls by id, or even loop through the Controls collection property of the Table1.
foreach (Control x in Table1.Controls)
{
if (x.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButton"))
{
if (((RadioButton)x).Checked)
{
//proceed.
}
}
}
Convert all controls to server controls (by adding the runat="server" attribute). You can then programatically access what you need o. The server.
How do I access data from html in asp.net in the .cs (code behind) file?
In .aspx page I have:
<tr>
<td>Username:</td><td><input id="username" type="text" /></td>
</tr>
<tr>
<td>Password:</td><td><input id="password" type="password" /></td>
</tr>
<tr>
I know I can convert this to something like:
<tr>
<td>Username:</td><td><asp:TextBox ID="username" TextMode="SingleLine" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td><td><asp:TextBox ID="password" TextMode="Password" runat=server></asp:TextBox></td>
</tr>
This will allow me to access the controls via IDs.
However I was wondering if there was a way of accessing data without using asp.net server-side controls.
Give the inputs a name as well as an id and you will be able to get the values from Request.Form. Inputs without names are not sent back with the form post.
<input id="username" name="username" type="text" />
<input id="password" name="password" type="password" />
var username = Request.Form["username"];
var password = Request.Form["password"];
Add runat="server" to the controls, and then you can access them from the code-behind almost as if they were <asp:______ /> controls.
ASP.NET controls, are in essence HTML controls wrapped, so an asp:Button will render as a input Html control.
Some web developers prefer using Html controls due to the smaller size.
Therefore each HTML control will map to a asp server control.
As the previous answer, from Joel, add the runat="server", then the control can be referenced by the ID from the code behind.
This is your code:
<tr>
<td>Username:</td>
<td><input id="username" type="text" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input id="password" type="password" /></td>
</tr>
You can just add the runat="server" attribute to the Html controls:
<tr>
<td>Username:</td>
<td><input id="username" runat="server" type="text" /> <!--NOTE THE RUNAT="SERVER"--></td>
</tr>
<tr>
<td>Password:</td>
<td><input id="password" **runat="server"** type="password" /></td>
</tr>
Now you can access the controls in asp.net.