【发布时间】:2014-12-16 01:57:38
【问题描述】:
我有一个 GridView,如下图所示,我想在其中显示 SQL Server 中存储过程的结果。根据其参数的输入,存储过程返回具有不同列数的不同结果。但是它的前两列始终是 measId 和 valSeq,它们在 GridView 中被视为 DataKeyNames。我想显示存储过程中的所有可用列,但 measId 和 valSeq。相反,我想显示 2 TemplateField。
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
DataSourceID="SqlDataSource1" Width="100%" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
CellSpacing="2" DataKeyNames="measId,valSeq"
onrowupdating="GridView_RowUpdating" Visible="False"
EmptyDataText="No data!" EnableModelValidation="True"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="cbCheckAll" runat="server" OnClick="javascript:selectAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" runat="server" />
</ItemTemplate>
<ItemStyle Width="25px" />
</asp:TemplateField>
<asp:CommandField HeaderText="Action" ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White"
Font-Names="Verdana" Font-Size="Small" HorizontalAlign="Left" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" Font-Names="Verdana"
Font-Size="X-Small" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
</asp:GridView>
我可以成功声明一个 SqlDataSource 以从存储过程中检索结果并将其与 GridView 绑定。 GridView 显示 TemplateFiled 以及从存储过程中检索到的所有列。现在我想隐藏 measId 和 valSeq 列。但我找不到任何方法来做到这一点。似乎我无法访问自动绑定到 GridView 的字段。
【问题讨论】: