首先,我“在asp.net中非常新,第二,对不起我的英语,
我用vb.net编写了这个.asp代码,并且设法显示gridview的数据。我还添加了以下代码行,以使整个行都可单击。
Private Sub AutoPopulateGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles AutoPopulateGridView.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.color='#47B6D2';"
e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='black';"
e.Row.ToolTip = "Click to view details"
End If
End Sub
我想要做的是,当用户单击每一行时,我将打开一个新页面,其中加载了用户单击该行所传递的新数据。而我被困在这里。
答案 0 :(得分:0)
您可以使用ASPx页面上的GridView模板来完成所有想要做的事情。
与其让GridView定义列本身,不如使用Templates定义它们,您可以在模板中在网格视图中添加控件。
将数据绑定到网格视图时,每列中的控件都会自动绑定到数据集。在下面,您可以看到一个使用数据表列my_value_database_column
的超链接列,该值被传递到GET或querystring上的新页面。 (以这种方式传递值是HTTP GET)。
<asp:GridView ID="AutoPopulateGridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="My Linked Column">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" href='MyNextPage.aspx?valueToPass=<%#Eval("my_value_database_column").ToString()%>'><%# Eval("column_name_with_text").ToString()%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="boring column" ItemStyle-CssClass="myHoverClass">
<ItemTemplate>
<%# Eval("other_datatable_column_name").ToString()%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
要获取在下一页传递的值,请在代码隐藏(.cs文件)中从查询字符串中检索值:
public partial class MyNextPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//first page hit
if (!IsPostBack)
{
Response.Write("THE VALUE PASSED WAS '" + Request.QueryString["valueToPass"] + "'");
}
}
}
此外,还可以使用CSS和psudo-class:hover
将样式直接添加到ASPx页面中的gridview模板中。<style type="text/css">
.myHoverClass {
text-decoration:none;
color:black;
}
.myHoverClass:hover {
cursor: pointer;
color: #47B6D2;
}
</style>
答案 1 :(得分:0)
此解决方案与您的解决方案有点不同。但是你可以从这里得到想法
此处的数据列表以表格格式显示,并在此处添加了可编辑链接,以便您了解如何使用html中的标记传递数据(实际上是项目ID)。
这是代码.............
<body>
<%
dim query
Dim objConn, objRS, sqlString
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("hospital.mdb")
set objRS = Server.CreateObject("ADODB.Recordset")
sqlString ="select * from Test"
objRS.Open sqlString, objConn
%>
<table class="table table-border table-hover table-striped">
<thead class="thead-dark">
<th>Test Name</th>
<th>Test Type</th>
<th>Unit Price</th>
<th>Date</th>
<th></th>
</thead>
<% Do Until objRs.EOF = True%>
<tr id="<%=objRS("iD")%>">
<td>
<%Response.Write(objRS("TestName"))%>
</td>
<td>
<%Response.Write(objRS("Type"))%>
</td>
<td>
<%Response.Write(objRS("UnitPrice"))%>
</td>
<td>
<%Response.Write(objRS("AddingDate"))%>
</td>
<td> <a href='editTest.asp?Id=<%=objRS("Id")%>'>Edit</a></td>
</tr>
<%
objRS.MoveNext
loop
objRS.Close
objConn.Close
%>
</table>
</body>