佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 獲取Repeter的Item和ItemIndex/CommandArgument實(shí)現(xiàn)思路與代碼

獲取Repeter的Item和ItemIndex/CommandArgument實(shí)現(xiàn)思路與代碼

熱門(mén)標(biāo)簽:電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) Linux服務(wù)器 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 阿里云 服務(wù)器配置 銀行業(yè)務(wù)
首先看看效果

Repeater控件,放在ItemTemplate內(nèi)的銨鈕OnClick之后,獲取Repeater的Item,ItemIndex,CommandArgument,CommandName以及綁定的字段值。
準(zhǔn)備數(shù)據(jù)
復(fù)制代碼 代碼如下:

View Code
Imports Microsoft.VisualBasic
Namespace Insus.NET
Public Class Catalog
Private _ID As Integer
Private _Name As String
Public Property ID As Integer
Get
Return _ID
End Get
Set(value As Integer)
_ID = 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
End Class
End Namespace

復(fù)制代碼 代碼如下:

View Code
Private Function GetData() As List(Of Catalog)
Dim cls As New List(Of Catalog)
Dim cl As Catalog = New Catalog()
cl.ID = 1
cl.Name = "汽車(chē)"
cls.Add(cl)
cl = New Catalog()
cl.ID = 2
cl.Name = "時(shí)尚"
cls.Add(cl)
cl = New Catalog()
cl.ID = 3
cl.Name = "科技"
cls.Add(cl)
cl = New Catalog()
cl.ID = 5
cl.Name = "文化"
cls.Add(cl)
cl = New Catalog()
cl.ID = 6
cl.Name = "公益"
cls.Add(cl)
Return cls
End Function

在.aspx放置Repeater控件:
復(fù)制代碼 代碼如下:

View Code
asp:Repeater ID="RepeaterCatalog" runat="server">
HeaderTemplate>
table border="1" cellpadding="3" cellspacing="0">
tr>
td>ID
/td>
td>Name
/td>
td>Choose/td>
/tr>
/HeaderTemplate>
ItemTemplate>
tr>
td>
asp:Label ID="LabelID" runat="server" Text='%# Eval("ID")%>'>/asp:Label>
/td>
td>
asp:Label ID="LabelName" runat="server" Text='%# Eval("Name")%>'>/asp:Label>
/td>
td>
asp:Button ID="Button1" runat="server" Text="Select" OnClick="Button1_Click" CommandArgument='%# Eval("ID")%>' CommandName="Choose" />
/td>
/tr>
/ItemTemplate>
FooterTemplate>
/table>
/FooterTemplate>
/asp:Repeater>

在.aspx.vb為Repeater控件綁定數(shù)據(jù)
復(fù)制代碼 代碼如下:

View Code
Imports Insus.NET
Partial Class Default2
Inherits System.Web.UI.Page
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.RepeaterCatalog.DataSource = GetData()
Me.RepeaterCatalog.DataBind()
End Sub
End Class

接下來(lái),我們寫(xiě)onclick事件,在寫(xiě)事件之前,先在.aspx放一個(gè)Label來(lái)顯示事件結(jié)果:
復(fù)制代碼 代碼如下:

Process infor:
asp:Label ID="LabelInfo" runat="server" Text="">/asp:Label>

復(fù)制代碼 代碼如下:

View Code
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim btn As Button = DirectCast(sender, Button)
Dim commandArgument As String = btn.CommandArgument
Dim commandName As String = btn.CommandName
Dim item As RepeaterItem = DirectCast(btn.NamingContainer, RepeaterItem)
Dim index As Integer = item.ItemIndex
Dim id As String = DirectCast(item.FindControl("LabelID"), Label).Text
Dim name As String = DirectCast(item.FindControl("LabelName"), Label).Text
Me.LabelInfo.Text = String.Format("Item index: {0}; CommandArgument: {1}; CommandName: {2}; ID: {3}; Name: {4};", index, commandArgument, commandName, id, name)
End Sub
您可能感興趣的文章:
  • 用Command對(duì)象和RecordSet對(duì)象向數(shù)據(jù)庫(kù)增加記錄哪一個(gè)更好
  • 使用Jmail及Winwebmail發(fā)信時(shí)系統(tǒng)記錄中的錯(cuò)誤:502 Error: command ...
  • Delphi Command模式
  • asp中command的在單條記錄時(shí),有些字段顯示為空的問(wèn)題
  • javascript document.execCommand() 常用解析
  • asp.net gridview的Rowcommand命令中獲取行索引的方法總結(jié)
  • php設(shè)計(jì)模式 Command(命令模式)
  • php設(shè)計(jì)模式 Command(命令模式)
  • 解決VS2012 Express的There was a problem sending the command to the program問(wèn)題
  • bash scp command not found的解決方法
  • GridView中動(dòng)態(tài)設(shè)置CommandField是否可用或可見(jiàn)的小例子
  • document.execCommand()的用法小結(jié)
  • pip 錯(cuò)誤unused-command-line-argument-hard-error-in-future解決辦法
  • 在RowCommand事件中獲取索引值示例代碼
  • ON_COMMAND_RANGE多個(gè)按鈕響應(yīng)一個(gè)函數(shù)的解決方法
  • C#命令模式(Command Pattern)實(shí)例教程
  • ASP基礎(chǔ)知識(shí)Command對(duì)象講解

標(biāo)簽:江蘇 廣元 衡水 大理 萍鄉(xiāng) 蚌埠 衢州 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《獲取Repeter的Item和ItemIndex/CommandArgument實(shí)現(xiàn)思路與代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    进贤县| 江源县| 天祝| 楚雄市| 平陆县| 石景山区| 米脂县| 大冶市| 灵丘县| 镇远县| 肥城市| 麦盖提县| 剑河县| 荔浦县| 柳林县| 云霄县| 东光县| 哈尔滨市| 石门县| 巧家县| 兴业县| 大英县| 临桂县| 璧山县| 咸宁市| 南召县| 西平县| 云霄县| 大庆市| 工布江达县| 铁岭县| 高雄市| 汉源县| 同江市| 绥江县| 循化| 夹江县| 江源县| 漠河县| 辉县市| 望城县|