ASP.Net สอบถามเรื่อง Link ใน GridView โดยใช้ HyperLink ลิงค์แล้วส่งค่าไปยังหน้าที่ต้องการ
สวัสดีครับ คือผมกำลังศึกษา asp.net โดยใช้ vb ผมมีข้อมูลที่ดึงออกมาแสดงในตารางโดยดึงจาก webservice เมื่อดึงข้อมูลมาโชว์แล้ว ผมต้องการให้มีปุ่ม edit del เมื่อคลิกไปแล้วส่งค่าในฟิวนั้นๆไปครับดังที่ผมแนบมาในภาพ เมื่อคลิกที่ edit จะลิงค์ไปหน้า estudent.aspx โดยส่งค่าตัวแปร student id ไปครับ ยังไงรบกวนผู้รู้ชี้แนะด้วยนะครับ
Code (VB.NET)
student.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="student.aspx.vb" Inherits="egco.student" %>
<!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>
<title>EGMU WEB SERVICE</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
<!--
.style3 {color: #FFFFFF}
.style5 {color: #000000}
.style13 {font-size: 16px}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.style22 {
font-size: 16px;
font-weight: bold;
color: #000000;
}
-->
</style>
</head>
<body>
<!-- BEGIN wrapper -->
<div id="wrapper">
<!-- BEGIN header -->
<div id="header">
<div class="buffer">
<div class="buffer">
<ul>
<li class="f2"><a href="">Faculty of Engineering</a></li>
<li class="f2"=><a href="">Mahidol University</a></li>
<li></li>
</ul>
<h1><a href="#">E - Learning</a></h1>
<ol>
<li class="f"><a href="admin.aspx">home</a></li>
<li class="f"></li>
<li class="f"></li>
<li class="f"></li>
<li class="f"><a href='student.aspx'>Student Database</a></li>
<li class="f"><a href='staff.aspx'>Staff Database</a></li>
<li class="f"><a href='news.aspx'>News</a></li>
</ol>
</div>
</div>
</div>
<!-- END header -->
<!-- BEGIN body -->
<div id="body">
<!-- BEGIN content -->
<div id="content">
<div class="buffer">
<!-- begin post -->
<div class="single">
<h2 class="style13"><span class="style3">STUDENT</span><br />
</h2>
<p>
<form id="frmMain2" runat="server">
<table width="467">
<tr>
<td width="101"><span class="style5"><strong>STUDENT ID</strong></span></td>
<td width="354"><label>
<input type="text" name="txtStid" id="txtStid" />
</label></td>
</tr>
<tr>
<td><span class="style5"><strong>NATION ID</strong></span></td>
<td><input type="text" name="txtNaid" id="txtNaid" /></td>
</tr>
<tr>
<td><span class="style5"><strong>NAME</strong></span></td>
<td><label>
<select name="txtSex" id="txtSex">
<option value="Mr.">Mr.</option>
<option value="Miss ">Miss</option>
</select>
</label>
<input type="text" name="txtName" id="txtName" /></td>
</tr>
<tr>
<td><span class="style5"><strong>SURNAME</strong></span></td>
<td><input type="text" name="txtSur" id="txtSur" /></td>
</tr>
<tr>
<td><span class="style5"><strong>DEPARTMENT</strong></span></td>
<td><select name="txtDep" id="txtDep">
<option value="Department of Civil and Environmental Engineering">Department of Civil and Environmental Engineering</option>
<option value="Department of Chemical Engineering">Department of Chemical Engineering</option>
<option value="Department of Mechanical Engineering">Department of Mechanical Engineering</option>
<option value="Department of Biomedical Engineering">Department of Biomedical Engineering</option>
<option value="Department of Computer Engineering">Department of Computer Engineering</option>
<option value="Department of Electrical Engineering">Department of Electrical Engineering</option>
<option value="Department of Industrial Engineering">Department of Industrial Engineering</option>
<option value="Department of TISM">Department of TISM</option>
</select></td>
</tr>
<tr>
<td><span class="style5"><strong>ADDRESS</strong></span></td>
<td><label>
<textarea name="textAdd" id="textAdd" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td><span class="style5"><strong>TELEPHONE</strong></span></td>
<td><input type="text" name="txtTel" id="txtTel" /></td>
</tr>
<tr>
<td><span class="style5"><strong>E-MAIL</strong></span></td>
<td><input type="text" name="txtMail" id="txtMail" /></td>
</tr>
<tr>
<td><span class="style5"><strong>TALENT</strong></span></td>
<td><input type="text" name="txtTa" id="txtTa" /></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="ADD" />
</label></td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="Black" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Width="696px">
<Columns>
<asp:BoundField DataField="stid" HeaderText="STUDENT ID">
<ControlStyle Width="1px" />
</asp:BoundField>
<asp:BoundField DataField="stname" HeaderText="NAME" >
<ControlStyle Width="10px" />
</asp:BoundField>
<asp:BoundField DataField="stsurname" HeaderText="SURNAME" />
<asp:BoundField DataField="stdep" HeaderText="DEPARTMENT" />
<asp:HyperLinkField HeaderText="EDIT" Text="EDIT">
<ControlStyle Width="2px" />
</asp:HyperLinkField>
<asp:HyperLinkField HeaderText="DEL" Text="DEL">
<ControlStyle Width="2px" />
</asp:HyperLinkField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
</p>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
</div>
<!-- END content -->
<!-- BEGIN sidebar -->
<div class="single2">
<div align="center">
<form action="?Action=Login" method="post" name="frmMain" id="frmMain">
<br />
<span class="style5"><strong><span class="style22"><asp:Label ID="lblCustomerID" runat="server"></asp:Label></span><br>
<br>
<br>
<a href="logout.aspx">Logout</a>
</form>
<p><span class="style5"><br />
</span><br />
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<!-- END sidebar -->
<div class="break"></div>
</div>
<!-- END body -->
<!-- BEGIN footer -->
<div id="footer">
<div align="center"><span class="style3"><strong>Department of Information Technology</strong> <br />
Faculty of Engineering, Mahidol University 25/25 Puttamonthon Nakorn Pathom 73170</span></div>
</div>
<!-- END footer -->
</div>
<!-- END wrapper -->
</body>
</html>
student.aspx.vb
Imports System.Web.Services
Public Class student
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsNothing(Session("strCustomerID")) Then
Response.Redirect("index.aspx")
Response.End()
End If
Dim cls As New clsGetCustomer.getCustomer
Dim myArr As Array = cls.resultCustomer(Session("strCustomerID"))
If myArr.Length > 0 Then
Me.lblCustomerID.Text = DataBinder.Eval(myArr(0), "username").ToString()
Session("department") = Me.lblCustomerID.Text
End If
Dim cls2 As New clsStudent.getCustomer
' myArr2 As Array = cls2.resultStudent(Session("department"))
Dim myArr2 As Array = DirectCast(cls2.resultStudent(Session("department")), Array)
Dim dt As DataTable
Dim dr As DataRow
dt = New DataTable()
dt.Columns.Add("stid")
dt.Columns.Add("stname")
dt.Columns.Add("stsurname")
dt.Columns.Add("stdep")
For Each arr In myArr2
dr = dt.NewRow()
dr("stid") = DataBinder.Eval(arr, "stid").ToString()
dr("stname") = DataBinder.Eval(arr, "stname").ToString()
dr("stsurname") = DataBinder.Eval(arr, "stsurname").ToString()
dr("stdep") = DataBinder.Eval(arr, "stdep").ToString()
dt.Rows.Add(dr)
Next
GridView1.DataSource = dt.DefaultView
GridView1.DataBind()
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
End Class
Tag : .NET, VB.NET
Date :
2013-02-20 02:29:05
By :
buu
View :
2307
Reply :
2
hyperlinkfield ไม่เห็นกำหนด datafieldname กับ navidatefield เลย
Date :
2013-02-20 09:10:27
By :
ห้ามตอบเกินวันละ 2 กระทู้
ได้ละครับ ขอบคุณมากเลยครับ
Date :
2013-02-20 11:08:41
By :
buu
Load balance : Server 02