You have to turn off the automatic use of columns and build them by hand.
The grid Property sheet can help - but once you see how it is done, it is
just as easy to directly edit the HTML and bind only those fields you want
to display.
Keep the datasource in Session for postbacks.
When the page is posted back you can define which row in the datasource was
selected (if you have a button in each row) and then you can use that index
value to identify all the info about that row in your datasource and get the
right Characteristic ID.
e.g. Note: OnItemCommand="GetRowInfo" (this method must defined in your code
behind.)
<asp:datagrid id="dg1" runat="server" Width="95%"
HorizontalAlign="Center"
BackColor="White" CellPadding="4" AllowSorting="True"
AutoGenerateColumns="False" GridLines="None"
CellSpacing="2" AllowPaging="True" PageSize="20" EnableViewState="False"
OnItemCommand="GetRowInfo">
<AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
<ItemStyle Wrap="False"></ItemStyle>
<PagerStyle NextPageText="Next" PrevPageText="Previous" Wrap="False"
Mode="NumericPages"></PagerStyle>
<Columns>
<asp:BoundColumn DataField="myName" SortExpression="myName"
HeaderText="My Name"></asp:BoundColumn>
<asp:BoundColumn DataField="sometext" SortExpression="sometext"
HeaderText="Active"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Choose Row">
<ItemTemplate>
<asp:imagebutton CommandName="btnEdit" id="btnEdit"
runat="server" ImageUrl="~/img/edit.gif" ToolTip="Edit"></asp:imagebutton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Protected Sub GetRowInfo(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)
'Grid paging/sorting causes this event to fire and e.Item.ItemIndex=-1
so we should avoid an error by coding for this case.
If e.Item.ItemIndex >= 0 Then
'get the index of the row in the grid (which is also the index for
your data source)
Dim mIndex As Integer = CType(source, DataGrid).PageSize *
CType(source, DataGrid).CurrentPageIndex + e.Item.ItemIndex
If e.CommandName = "btnEdit" Then
Session("myKey") = myList(mIndex).myKey
'the page below expects a value of myKey to be in Session since you
chose it from the page with the grid.
Response.Redirect("~/MyEditPage.aspx")
End If
End If
End Sub