此表格抓取用户ID的输入以获取分配的车辆列表,然后用户将需要输入表格中显示的每辆车的里程数,并且列表将与输入的里程数一起保存,问题是我我有无法获取我需要发送到数据库的里程数,当我将其发送到代码隐藏时,stringify会出现。我很欣赏任何建议或指向正确的方向。
- 使用Javascript -
<script type="text/javascript" src="Scripts/jquery.tabletojson.min.js"></script>
<script type="text/javascript">
//Get the User ID input
$(document).ready(function () {
$('#btnSearch').click(function () {
// alert("something");
userInfo();
});
function userInfo() {
var elem_id = $("#txtIBMEntry").val();
var page_url = "MileageEntry.aspx/GetServices";
$.ajax({
type: "POST",
url: page_url,
data: "{'IBM':'" + elem_id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (userDetails)
{ $("#infoDisplay").html(userDetails.d); }
});
//return false;
};
$('#btnSave').click(function () {
// alert("This is going to activate the save procedure");
setVehicleMileage();
});
function setVehicleMileage() {
var page_urlSave = "MileageEntry.aspx/SetVehicleMileage";
//var tbl = $('#results tr');
var tbl = $('#results').tableToJSON();
var table = JSON.stringify(tbl);
$.ajax({
type: "POST",
url: page_urlSave,
data: "{'tbl':'" + table + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (userDetails1)
{ $("#infoDisplay").html(userDetails1.d); }
});
//alert(JSON.stringify(table));
};
});
</script>
这是我加载html表的方法,我使用相同的代码来显示输入里程的文本框
Public Shared Function GetString(ByVal IBM As String)
'vb code
Dim ds As New DataSet
IBM = Right("00000" & IBM, 5)
ds = DBMgr.GetAssignedVeh(IBM)
Dim table As DataTable = New DataTable()
table = ds.Tables(0)
Dim drows As DataRowCollection = table.Rows
Dim HTML As StringBuilder = New StringBuilder
' HTML.AppendLine("<table>")
If drows.Count > 0 Then
HTML.Append("<table id='results' style='border-width:1; border-color:Silver; border-style:solid; padding:4;'>")
HTML.Append("<thead>")
HTML.Append("<tr><th>Name/IBM</th><th>Vehicle </th><th>Vehicle Number</th><th>Mileage</th>")
HTML.Append("</tr>")
HTML.Append("</thead>")
For Each dr As DataRow In drows
HTML.Append("<tbody>")
HTML.AppendLine("<tr>")
HTML.AppendFormat("<td>{0}  </td>" & vbLf, dr("AssignedIBM"))
HTML.AppendFormat("<td>{0}  </td>" & vbLf, dr("VehicleName"))
HTML.AppendFormat("<td>{0} </td>" & vbLf, dr("VehNum"))
HTML.AppendFormat("<td>{0} <input id='txtMileageEntry'/></td>" & vbLf, "")
HTML.AppendLine("</tr>")
Next
HTML.AppendLine("<tr>")
HTML.AppendLine("<td colspan=3> </td>")
HTML.AppendLine("<td></td>")
HTML.AppendLine("</tr>")
HTML.Append("</tbody>")
HTML.AppendLine("</table>")
'HTML.AppendLine("</div>")
'<input type='button' id='btnSave1' value='Save Mileage' />
Else : HTML.AppendLine("<label id='lblMessage'style='color:Red ;' >IBM Entered does not match any records, Please try again.</label>")
End If
Return HTML.ToString
End Function