GridView绑定试题及答案

本文介绍如何使用 ASP.NET 中的 GridView 控件实现数据分页显示及动态绑定数据源的方法。通过配置 GridView 的属性如 AllowPaging 和 PageSize 实现每页显示记录数的控制,并通过设置 DataKeyNames 和 onpageindexchanging 属性实现页面跳转的功能。此外,还展示了如何在 ItemTemplate 中嵌套使用 HiddenField 和 RadioButtonList 控件来实现复杂的数据展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                        AllowPaging="True" PageSize="4"
                        DataKeyNames="questionCode"
                                EnableSortingAndPagingCallbacks="True" Width="780px"
                                onpageindexchanging="GridView1_PageIndexChanging">
                                <PagerSettings FirstPageText="首页" LastPageText="尾页"
                            Mode="NextPreviousFirstLast" NextPageText="下一页" PreviousPageText="上一页" />
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <table>
                                                <tr>
                                                    <td align=left>
                                                        <asp:HiddenField ID="hditem" runat="server"
                                        Value='<%# Eval("questionCode") %>' />
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("contents") %>'></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align=left>
                                                        <asp:RadioButtonList ID="RadioButtonList1" runat="server"
                                        DataSourceID="getAnsDS" DataTextField="ansContents"
                                        DataValueField="ansCode" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                                                        </asp:RadioButtonList>
                                                        <asp:SqlDataSource ID="getAnsDS" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:HST_KSConnectionString %>"
                                        SelectCommand="GetAns" SelectCommandType="StoredProcedure">
                                                            <SelectParameters>
                                                                <asp:ControlParameter ControlID="hditem" Name="questionCode"
                                                PropertyName="Value" Type="String" />
                                                            </SelectParameters>
                                                        </asp:SqlDataSource>
                                                    </td>
                                                </tr>
                                            </table>
                                        </ItemTemplate>
                                       

                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wangjiaotou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值