views:

871

answers:

2

In ASP.NET 3.5, you can assign a Select link and change what the link actually displays. But can you you assign one of the fields in the gridview to act as a select button?

For instance, all my records have a "SAMPLE ID" Field. It would be great to have each unique SAMPLE ID be a link that goes to the details view. I cannot find any setting under the gridview 'edit columns' that appears to assign that behavior to a certain field.

I know this has to be possible because I rarely see ASP.NET websites that actually use the "Select" link on the side - most of them let you click one of the fields.

How can I do this?

Using Visual Studio 2008, ASP.NET 3.5, and C# 3.0!

+1  A: 

You can use a template field and bind a LinkButton to the "SAMPLE ID". I don't have VS handy to test this - but should get you started...

<asp:TemplateField HeaderText="Sample Id">
    <ItemTemplate>
     <asp:LinkButton runat="server" CommandName="Select" Text='<%#Bind("SAMPLE ID")#>'></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>
russau
+3  A: 

I would add a ButtonField with the DataTextField as the database table column you want to bind it to, and make the CommandName "Select". I just did this in Visual Web Developer 2008 Express on a GridView and it worked. Good luck!

Thomas Arnold