时间:2021-05-28
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>
动画演示:
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
前一版本https://www.jb51.net/article/33251.htm是用Javascript获取GridView的行索引。此篇Insus.NET
本文实例讲述了DevExpress实现根据行,列索引来获取RepositoryItem的方法,具体方法如下:主要功能代码如下://////根据行,列索引来获取R
一、通过命令源获取当前行索引。方法比较多,GridView的Command事件中无法象DataGrid那样直接获取行,法1,GridViewRowdrv=((G
Android实现获取手机里面的所有图片详解及实例实现代码:publicclassMainActivityextendsActivity{//查看图片按钮pri
在实际项目开发中,我找到了一种利用GridView实现分级效果的方法,最终效果图如下:以下是实现代码:Aspx页面复制代码代码如下:后台代码复制代码代码如下:P