Insus.NET为了演示这个例子,首先准好数据,创建一个类别
Cosmetic.vb
复制代码 代码如下:
Imports Microsoft.VisualBasic
Namespace Insus.NET
Public Class Cosmetic
Private _ID As Integer
Private _Type As String
Private _Name As String
Private _Weight As Decimal
Private _UM As String
Public Property ID As Integer
Get
Return _ID
End Get
Set(value As Integer)
_ID = value
End Set
End Property
Public Property Type As String
Get
Return _Type
End Get
Set(value As String)
_Type = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Public Property Weight As Decimal
Get
Return _Weight
End Get
Set(value As Decimal)
_Weight = value
End Set
End Property
Public Property UM As String
Get
Return _UM
End Get
Set(value As String)
_UM = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(id As Integer, type As String, name As String, weight As Decimal, um As String)
Me._ID = id
Me._Type = type
Me._Name = name
Me._Weight = weight
Me._UM = um
End Sub
End Class
End Namespace
上面创建好的只是一对象,得需用数据填充,让它有血有肉有灵魂。
复制代码 代码如下:
Private Function GetData() As List(Of Cosmetic)
Dim o As New List(Of Cosmetic)
Dim c As New Cosmetic(1, "滋润霜", "玉兰油", 50, "g")
o.Add(c)
Dim c1 As New Cosmetic(2, "滋润霜", "雅诗兰黛", 100, "g")
o.Add(c1)
Dim c2 As New Cosmetic(3, "滋润霜", " 兰蔻", 80, "g")
o.Add(c2)
Dim c3 As New Cosmetic(4, "滋润霜", "欧莱雅", 60, "g")
o.Add(c3)
Dim c4 As New Cosmetic(5, "滋润霜", "芭比波朗", 120, "g")
o.Add(c4)
Return o
End Function
在aspx网页上放一个Gridview控件:
复制代码 代码如下:
<asp:GridView ID="GridViewCosmetic" runat="server" Width="300" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
ID
</HeaderTemplate>
<ItemTemplate>
<%# Eval("ID")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Type
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Type")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Right" />
<HeaderTemplate>
Weight
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Weight")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
UM
</HeaderTemplate>
<ItemTemplate>
<%# Eval("UM") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
当然得对这个控件,进行数据绑定,引用命名空间Imports Insus.NET
复制代码 代码如下:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Data_Binding()
End If
End Sub
Private Sub Data_Binding()
Me.GridViewCosmetic.DataSource = GetData()
Me.GridViewCosmetic.DataBind()
End Sub
接下来,我们开始演示,在GridView控件最后一列,添加一列,选择列:
复制代码 代码如下:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text="选择" OnClientClick="return GetSelectedRow(this)" />
</ItemTemplate>
</asp:TemplateField>
上面html代码中,有一个OnClientClick="return GetSelectedRow(this)" 客户端事件。
复制代码 代码如下:
<script type="text/javascript">
function GetSelectedRow(obj) {
var row = obj.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
alert("你选择的行索引是:" + rowIndex);
return false;
}
</script>
动画演示:
Cosmetic.vb
复制代码 代码如下:
Imports Microsoft.VisualBasic
Namespace Insus.NET
Public Class Cosmetic
Private _ID As Integer
Private _Type As String
Private _Name As String
Private _Weight As Decimal
Private _UM As String
Public Property ID As Integer
Get
Return _ID
End Get
Set(value As Integer)
_ID = value
End Set
End Property
Public Property Type As String
Get
Return _Type
End Get
Set(value As String)
_Type = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Public Property Weight As Decimal
Get
Return _Weight
End Get
Set(value As Decimal)
_Weight = value
End Set
End Property
Public Property UM As String
Get
Return _UM
End Get
Set(value As String)
_UM = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(id As Integer, type As String, name As String, weight As Decimal, um As String)
Me._ID = id
Me._Type = type
Me._Name = name
Me._Weight = weight
Me._UM = um
End Sub
End Class
End Namespace
上面创建好的只是一对象,得需用数据填充,让它有血有肉有灵魂。
复制代码 代码如下:
Private Function GetData() As List(Of Cosmetic)
Dim o As New List(Of Cosmetic)
Dim c As New Cosmetic(1, "滋润霜", "玉兰油", 50, "g")
o.Add(c)
Dim c1 As New Cosmetic(2, "滋润霜", "雅诗兰黛", 100, "g")
o.Add(c1)
Dim c2 As New Cosmetic(3, "滋润霜", " 兰蔻", 80, "g")
o.Add(c2)
Dim c3 As New Cosmetic(4, "滋润霜", "欧莱雅", 60, "g")
o.Add(c3)
Dim c4 As New Cosmetic(5, "滋润霜", "芭比波朗", 120, "g")
o.Add(c4)
Return o
End Function
在aspx网页上放一个Gridview控件:
复制代码 代码如下:
<asp:GridView ID="GridViewCosmetic" runat="server" Width="300" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
ID
</HeaderTemplate>
<ItemTemplate>
<%# Eval("ID")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Type
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Type")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Right" />
<HeaderTemplate>
Weight
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Weight")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
UM
</HeaderTemplate>
<ItemTemplate>
<%# Eval("UM") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
当然得对这个控件,进行数据绑定,引用命名空间Imports Insus.NET
复制代码 代码如下:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Data_Binding()
End If
End Sub
Private Sub Data_Binding()
Me.GridViewCosmetic.DataSource = GetData()
Me.GridViewCosmetic.DataBind()
End Sub
接下来,我们开始演示,在GridView控件最后一列,添加一列,选择列:
复制代码 代码如下:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text="选择" OnClientClick="return GetSelectedRow(this)" />
</ItemTemplate>
</asp:TemplateField>
上面html代码中,有一个OnClientClick="return GetSelectedRow(this)" 客户端事件。
复制代码 代码如下:
<script type="text/javascript">
function GetSelectedRow(obj) {
var row = obj.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
alert("你选择的行索引是:" + rowIndex);
return false;
}
</script>
动画演示:
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]