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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GridView添加自动编号列

發布時間:2025/5/22 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GridView添加自动编号列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在開發中使用的GridView顯示數據,并且需要它記錄集的行編號,這樣就可以很清楚的知道有多少條數據。

通過查看資料,自己做了個GridView模板,并帶有分頁功能示例:

Code
<asp:GridView?ID="GView_Data"?runat="server"?AllowPaging="True"?Height="1px"?Font-Size="10pt"?BackColor="White"?BorderColor="#E7E7FF"?BorderWidth="1px"?OnRowDataBound="GView_Data_RowDataBound"?>??
????????????????
<Columns>
????????????????????
<asp:TemplateField?HeaderText="序號"?InsertVisible="False"?ControlStyle-Width="20px"?>
?????????????????????????
<headerstyle?width="5%"?horizontalalign="Center"?/>
?????????????????????????
<ItemTemplate>
????????????????????????????
<asp:Label?id="Label2"?runat="server"?Width="100%"?Text="<%#?this.GView_Data.PageIndex?*?this.GView_Data.PageSize??+?this.GView_Data.Rows.Count?+?1?%>"?ForeColor="Blue"></asp:Label>?
?????????????????????????
</ItemTemplate>
????????????????????
</asp:TemplateField>
????????????????
</Columns>
????????????????
<PagerTemplate>
????????????????????
<table?width="100%">
????????????????????????
<tr>
????????????????????????????
<td?style="text-align:?left">
????????????????????????????????第
<asp:Label?ID="lblPageIndex"?runat="server"?Text='<%#?((GridView)Container.Parent.Parent).PageIndex?+?1??%>'></asp:Label>
????????????????????????????????共
/<asp:Label?ID="lblPageCount"?runat="server"?Text='<%#?((GridView)Container.Parent.Parent).PageCount??%>'></asp:Label>
????????????????????????????????
<asp:LinkButton?ID="btnFirst"?runat="server"?CausesValidation="False"?CommandArgument="First"
????????????????????????????????????CommandName
="Page"?Text="首頁"?OnClick="LinkBtn_Sjy_Click"></asp:LinkButton>
????????????????????????????????
<asp:LinkButton?ID="btnPrev"?runat="server"?CausesValidation="False"?CommandArgument="Prev"
????????????????????????????????????CommandName
="Page"?Text="上一頁"?OnClick="LinkBtn_Sjy_Click"></asp:LinkButton>
????????????????????????????????
<asp:LinkButton?ID="btnNext"?runat="server"?CausesValidation="False"?CommandArgument="Next"
????????????????????????????????????CommandName
="Page"?Text="下一頁"?OnClick="LinkBtn_Sjy_Click"></asp:LinkButton>
????????????????????????????????
<asp:LinkButton?ID="btnLast"?runat="server"?CausesValidation="False"?CommandArgument="Last"
????????????????????????????????????CommandName
="Page"?Text="尾頁"?OnClick="LinkBtn_Sjy_Click"></asp:LinkButton>
????????????????????????????????
<asp:TextBox?ID="txtNewPageIndex"?runat="server"?Text='<%#?((GridView)Container.Parent.Parent).PageIndex?+?1??%>'
????????????????????????????????????Width
="20px"></asp:TextBox>
????????????????????????????????
<asp:LinkButton?ID="btnGo"?runat="server"?CausesValidation="False"?CommandArgument="Go"
????????????????????????????????????CommandName
="Page"?Text="GO"?OnClick="LinkBtn_Sjy_Click"></asp:LinkButton><!--?here?set?the?CommandArgument?of?the?Go?Button?to?'-1'?as?the?flag?-->
????????????????????????????
</td>
????????????????????????
</tr>
????????????????????
</table>
????????????????????
</PagerTemplate>
????????????????????
<FooterStyle?BackColor="#B5C7DE"?ForeColor="#4A3C8C"?/>
????????????????????
<RowStyle?BackColor="#E7E7FF"?ForeColor="#4A3C8C"?/>
????????????????????
<PagerStyle?BackColor="#E7E7FF"?ForeColor="#4A3C8C"?HorizontalAlign="Right"?/>
????????????????????
<SelectedRowStyle?BackColor="#738A9C"?Font-Bold="True"?ForeColor="#F7F7F7"?/>
????????????????????
<HeaderStyle?BackColor="#7481BA"?Font-Bold="True"?ForeColor="Yellow"?HorizontalAlign="Left"?Wrap="False"?/>
????????????????????
<AlternatingRowStyle?BackColor="#F7F7F7"?/>
</asp:GridView>

?

分頁功能實現方法省略。

?

總結

以上是生活随笔為你收集整理的GridView添加自动编号列的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。