日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GridView行号大集合

發(fā)布時(shí)間:2025/3/8 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GridView行号大集合 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
aspx頁面: <asp:GridView ID="gvDataInfo" runat="server" AutoGenerateColumns="False" OnRowCommand="gvDataInfo_RowCommand">
??????????????????? <Columns>
??????????????????????? <asp:BoundField DataField="job_id" HeaderText="編號" />
??????????????????????? <asp:TemplateField>
??????????????????????????? <ItemTemplate>
??????????????????????????????? <asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged">
??????????????????????????????????? <asp:ListItem Value="-1">-請選擇-</asp:ListItem>
??????????????????????????????????? <asp:ListItem Value="0">測試1</asp:ListItem>
??????????????????????????????????? <asp:ListItem Value="1">測試2</asp:ListItem>
??????????????????????????????????? <asp:ListItem Value="2">測試3</asp:ListItem>
??????????????????????????????? </asp:DropDownList>
??????????????????????????? </ItemTemplate>
??????????????????????? </asp:TemplateField>
??????????????????????? <asp:TemplateField>
??????????????????????????? <ItemTemplate>
??????????????????????????????? <asp:CheckBox ID="cbTest" runat="server" AutoPostBack="True" OnCheckedChanged="cbTest_CheckedChanged" />
??????????????????????????? </ItemTemplate>
??????????????????????? </asp:TemplateField>
??????????????????????? <asp:BoundField DataField="job_desc" HeaderText="職位描述" />
??????????????????????? <asp:BoundField DataField="min_lvl" HeaderText="最小值" />
??????????????????????? <asp:BoundField DataField="max_lvl" HeaderText="最大值" />
??????????????????????? <asp:TemplateField HeaderText="操作">
??????????????????????????? <ItemTemplate>
??????????????????????????????? <asp:LinkButton ID="lbTestOne" runat="server" CommandName="one">RowCommand事件</asp:LinkButton>
??????????????????????????????? <asp:LinkButton ID="lbTestCommand" runat="server" CommandName="two" OnCommand="lbTestCommand_Command">LinkButton的Command事件</asp:LinkButton>
??????????????????????????????? <asp:LinkButton ID="lbTestClick" runat="server" OnClick="lbTestClick_Click">LinkButton的Click事件</asp:LinkButton>
??????????????????????????? </ItemTemplate>
??????????????????????? </asp:TemplateField>
??????????????????? </Columns>
??????????????? </asp:GridView>
aspx.cs頁面: ??? /// <summary>
??? /// 行綁定事件
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void gvDataInfo_RowCommand(object sender, GridViewCommandEventArgs e)
??? {
??????? if (e.CommandName == "one")
??????? {
??????????? GridViewRow drv = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
??????????? //GridViewRow drv = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //上下兩種方式都可以
??????????? int index = drv.RowIndex;//獲取行號
??????????? Response.Write("<script>alert("+index+");</script>");//行號從0開始
??????? }
??? }
??? /// <summary>
??? /// LinkButton的Command事件
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void lbTestCommand_Command(object sender, CommandEventArgs e)
??? {
??????? LinkButton lb = (LinkButton)sender;
??????? DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent; ??????? GridViewRow gvr = (GridViewRow)dcf.Parent; ??????? int index = gvr.RowIndex;//獲取行號
??????? Response.Write("<script>alert(" + index + ");</script>");//行號從0開始

??? }
??? /// <summary>
??? /// LinkButton的Click事件
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void lbTestClick_Click(object sender, EventArgs e)
??? {
??????? GridViewRow gvr = (GridViewRow)((LinkButton)sender).NamingContainer;
??????? int index = gvr.RowIndex;//獲取行號
??????? Response.Write("<script>alert(" + index + ");</script>");//行號從0開始
??? }
??? /// <summary>
??? /// DropDownList獲取當(dāng)前行
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
??? {
??????? DropDownList ddl = (DropDownList)sender;
??????? GridViewRow gvr = (GridViewRow)ddl.NamingContainer; ??????? int index = gvr.RowIndex;//獲取行號
??????? Response.Write("<script>alert(" + index + ");</script>");//行號從0開始
??? }
??? /// <summary>
??? /// CheckBox獲取當(dāng)前行
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void cbTest_CheckedChanged(object sender, EventArgs e)
??? {
??????? CheckBox chk = (CheckBox)sender;
??????? DataControlFieldCell dcf = (DataControlFieldCell)chk.Parent; ??????? GridViewRow gvr = (GridViewRow)dcf.Parent; ??????? int index = gvr.RowIndex;//獲取行號
??????? Response.Write("<script>alert(" + index + ");</script>");//行號從0開始
??? }



本文轉(zhuǎn)自 韜光星夜 51CTO博客,原文鏈接:http://blog.51cto.com/xfqxj/477082,如需轉(zhuǎn)載請自行聯(lián)系原作者

總結(jié)

以上是生活随笔為你收集整理的GridView行号大集合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。