欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

GridView/DataGrid 整行添加服務(wù)器事件

系統(tǒng) 1623 0

需求說明

GridView/DataGrid 本身均支持行選擇事件(通過設(shè)置Button/LinkButton.CommandName="Selected",并在 SelectedIndexChanged 事件中處理)。
然而,有時(shí)候我們希望用戶點(diǎn)擊 GridView/DataGrid 一行中任意位置都可以實(shí)現(xiàn)觸發(fā)一個(gè)事件,并在服務(wù)端對(duì)此行進(jìn)行相應(yīng)處理,現(xiàn)在我們就實(shí)現(xiàn)此功能。

實(shí)現(xiàn)方式

這里我們采取的方法有點(diǎn) "hack" :
通過客戶端 javascript 引發(fā)行中隱藏的按鈕(Button/LinkButton 均可以)的 click 事件。

主要代碼

< asp:GridView ID ="GridView1" runat ="server" AutoGenerateColumns ="false" OnRowCommand ="GridView1_RowCommand" OnRowDataBound ="GridView1_RowDataBound" >
< Columns >
< asp:TemplateField HeaderText ="ProductName" >
< ItemTemplate >
<% # Eval ( " ProductName " ) %>
< asp:Button ID ="btnHiddenPostButton" CommandName ="HiddenPostButtonCommand" runat ="server" Text ="HiddenPostButton" style ="display:none" />
</ ItemTemplate >
</ asp:TemplateField >
< asp:BoundField DataField ="UnitPrice" HeaderText ="UnitPrice" />
</ Columns >
</ asp:GridView >
protected void GridView1_RowDataBound( object sender,GridViewRowEventArgse)
{
ButtonbtnHiddenPostButton
= e.Row.FindControl( " btnHiddenPostButton " ) as Button;
if (btnHiddenPostButton != null ) {
e.Row.Attributes[
" onclick " ] = String.Format( " javascript:document.getElementById('{0}').click() " ,btnHiddenPostButton.ClientID);
// 額外樣式定義
e.Row.Attributes[ " onmouseover " ] = " javascript:this.style.background='red' " ;
e.Row.Attributes[
" onmouseout " ] = " javascript:this.style.background='' " ;
e.Row.Attributes[
" style " ] = " cursor:pointer " ;
e.Row.Attributes[
" title " ] = " 單擊選擇當(dāng)前行 " ;
}

// 若希望將隱藏按鈕單獨(dú)放于一列,則設(shè)置此列隱藏,占位符<cellIndex>表示此列索引
// e.Row.Cells[<cellIndex>].Attributes["style"]="display:none";
}


protected void GridView1_RowCommand( object sender,GridViewCommandEventArgse)
{
int rowIndex = - 1 ;
GridViewRowrow
= null ;
switch (e.CommandName) {
case " HiddenPostButtonCommand " : // 模板列
ControlcmdControl = e.CommandSource as Control; // 表示觸發(fā)事件的IButtonControl,保持統(tǒng)一性并便于后續(xù)操作,我們這里直接轉(zhuǎn)化為控件基類Control
row = cmdControl.NamingContainer as GridViewRow; // 當(dāng)前行
// 如何訪問單元格值
// stringtxt=row.Cells[0].Text;
// 如何獲取模板列中的Label
// stringlbl=row.FindControl("MyLabelID")asLabel;
// 執(zhí)行更多的自定義操作
//
//
Response.Write(String.Format( " GridViewVersion當(dāng)前第{0}行: " ,row.RowIndex + 1 ));
break ;
// case"Command2":
// morecases
//
}

}



測(cè)試效果

GridView/DataGrid 整行添加服務(wù)器事件

GridView/DataGrid 整行添加服務(wù)器事件


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 亚洲色综合图区p | 天天做天天爽 | 日韩成人免费观看 | www.妞干网.com | 久久99热久久精品23 | 久久国产精品-国产精品 | 好骚综合在线 | 五月婷婷社区 | 国产一区二区三区久久久久久久久 | 天天操网 | 91综合视频 | 成年视频在线观看免费 | 91精品网| 视频一区在线观看 | 天天看片网站 | 色狠狠狠色噜噜噜综合网 | 久久小视频 | 天天操伊人 | 精精国产xxxx视频在线 | 夜夜夜夜猛噜噜噜噜噜 | 欧美老妇69交 | 黄色免费av | 久久精品亚洲欧美日韩精品中文字幕 | 亚洲国产品综合人成综合网站 | 国产精品伊人 | 狠狠综合久久综合鬼色 | 免费精品久久 | 国产精品久久久久久亚洲色 | 激情小说图 | 一区二区免费在线观看 | 国产精品一区二区三区久久 | 蜜桃五月天| 2020国产精品视频免费 | 亚州中文字幕 | av电影网站在线观看 | 午夜精品小视频 | 羞羞的动漫在线观看 | 成人免费网址在线 | 欧美高清在线精品一区二区不卡 | 久久精品伊人网 | 5060午夜网|