I have a GridView, as illustrated below, in which I want to display the results from a Stored Procedure in SQL Server. Depenting on inputs of its arguments, The stored procedure returns different results with different number of columns. However its first two columns are always measId and valSeq, which are considered as DataKeyNames in the GridView. I want to display all the available columns in the stored procedure, but measId and valSeq. Instead I want to display 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>
I could successfully declare a SqlDataSource to retrieve the results from the stored procedure and bound it with the GridView. The GridView displays the TemplateFileds as well as all the retrieved columns from the stored procedure. Now I want to hide measId and valSeq columns. But I couldn't find any way to do that. It seems that I cannot have access to the fields which are automatically bound to the GridView.