欧美三区_成人在线免费观看视频_欧美极品少妇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)論
主站蜘蛛池模板: 国产99页 | 福利免费在线观看 | 久久制服丝袜 | 成人在线精品 | 国产日韩欧美一区 | 99热精品在线观看 | 三上悠亚2022年最新番号 | 国产不卡视频在线 | 黄页网站免费高清在线观看 | 男人的天堂av2017在线 | 国产色综合天天综合网 | 成人毛片100免费观看 | 懂色一区二区三区免费观看 | 欧美欧美欧美 | 999精品久久久 | 香蕉成人国产精品免费看网站 | 国产孰妇精品AV片国产m3u8 | 国产精品网址在线观看你懂的 | 欧美精品一区二区在线电影 | 成人欧美一区在线视频在线观看 | 在线国产一区 | 很黄很色的小视频在线网站 | 色天天天天综合男人的天堂 | 免费国产成人午夜在线观看 | 日韩在线不卡 | 五月综合色 | com.色.www在线观看 | 久久综合伊人 | 亚洲一区二区三 | 国产福利不卡视频在免费播放 | 中文字幕日韩欧美 | 十六以下岁女子毛片免费 | 亚洲综合综合在线 | 日本wwxx | 黄网站在线观看 | 色网站在线免费观看 | 欧美激情综合网 | 99热久久这里只有精品6国产网 | www.嫩草影院.com | 欧美另类专区 | 一区二区三区 日韩 |