我有一个gridview,在我的数据库中有一个ID列 - WorkHoursNotRecordID,我试图将值传递给新的网页。除了此ID之外,我可以将所有其他值传递到新网页。在我的SQL数据库中,它是表中的主键。我想我的语法有些错误,但我无法弄明白。我将尝试只包含具有此WorkHoursNotRecordID的代码。
在Gridview网页aspx:
<asp:BoundField DataField="WorkHoursNotRecordID"
ItemStyle-Width="120px"
SortExpression="Description" />
...
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeSQLConnectionString1 %>"
SelectCommand="SELECT tblWorkHoursNotRecord.EmployeeName, tblWorkHoursNotRecord.BeginDateOff, tblWorkHoursNotRecord.EndDateOff, tblWorkHoursNotRecord.AllDay_YesNo, tblWorkHoursNotRecord.BeginTimeOff, tblWorkHoursNotRecord.EndTimeOff, tblEmployees.Login, tblCodesWorkNotRec.Description, tblWorkHoursNotRecord.WorkHoursNotRecordID FROM tblWorkHoursNotRecord INNER JOIN tblCodesWorkNotRec ON tblWorkHoursNotRecord.WorkCode = tblCodesWorkNotRec.WorkCodeID INNER JOIN tblEmployees ON tblWorkHoursNotRecord.Employee = tblEmployees.EmployeeID WHERE (tblEmployees.Login = @username) ORDER BY tblWorkHoursNotRecord.BeginDateOff DESC"
OnSelecting="SqlDataSource1_Selecting">
<SelectParameters>
<asp:QueryStringParameter Name="username" />
</SelectParameters>
</asp:SqlDataSource>
在Gridview网页vb:
中Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow
If row IsNot Nothing Then
'Change the cell index number as per your grid cell index
Response.Redirect("TimeOffNoRequestEdit.aspx?BeginDateOff=" + row.Cells(1).Text.ToString() + "&EndDateOff=" + row.Cells(2).Text.ToString() + "&BeginTimeOff=" + row.Cells(4).Text.ToString() + "&EndTimeOff=" + row.Cells(5).Text.ToString() + "&AllDay_YesNo=" + CType(row.Cells(3).Controls(0), CheckBox).Checked.ToString() + "&WorkCode=" + row.Cells(6).Text.ToString() + "&Description=" + row.Cells(6).Text.ToString()) ', +"&WorkHoursNotRecordID=" + row.Cells(9).Text.ToString())
End If
End Sub
在新网页的aspx中:
<asp:TextBox ID="wkid" runat="server"></asp:TextBox>
在新网页的vb Page_load中:
wkid.Text = Request.QueryString("WorkHoursNotRecordID").ToString()
提前感谢你们给我的任何帮助!
答案 0 :(得分:0)
我的编码错误。我需要将代码wkid.Text = Request.QueryString(&#34; WorkHoursNotRecordID&#34;)。ToString()放在我已经结束的代码之前,如果另一个字段等于一个值。好吧,我一直在挑选错误的行进行测试,代码结束了,因为它等于值。刚交换了序列,它起作用了。谢谢你的帮助!