Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The Select command is one of the field and not a "Select" hyperlink in 2

Status
Not open for further replies.

destroyhead

Programmer
Feb 22, 2006
27
GB
Hello,

I have got a GridView with some columns and a Select column on the left with the Select hyperlink.

I want to delete the Select column and bind the Select command to the first column ("Name" for example) so that the user click on a Name to select a row rather than on the Select hyperlink.

Is it possible?

Thanks for your help.

Olivier
 
Oliver - I might be missing something here but this should be very straight forward, couldn't you simply do this:
Code:
<asp:TemplateColumn HeaderText="Name">
<HeaderStyle horizontalalign="Center" verticalalign="Middle"/>
 <ItemStyle horizontalalign="Center" width="40"/>
  <ItemTemplate>
   <asp:HyperLink 
    id=HyperLink1
    runat="server"
    Text='<%# DataBinder.Eval(Container, "DataItem.Name")%>'
    NavigateUrl='<%# "qwwDESites.aspx?GrpID=" & DataBinder.Eval(Container, "DataItem.GrpID") & "&GroupName=" & DataBinder.Eval(Container, "DataItem.Group_Name")%>'
   />
 </ItemTemplate>
</asp:TemplateColumn>
..or perhaps there is something else you are referring to?
 
Hi Isadore,

Thanks very much for your answer.

Actually, I was wondering if I could do that with a GridView databound from an SQLDataSource.

Here is my code :

<asp:GridView CellSpacing="0" ID="GridViewResults" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="ESXHostID,ServerID" DataSourceID="SearchResults" OnSelectedIndexChanged="GridViewResults_SelectedIndexChanged" OnRowDataBound="GridViewResults_RowDataBound1" ForeColor="Black" Width="100%" GridLines="None">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ServerName" HeaderText="Server Name" SortExpression="ServerName" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="CAB" HeaderText="CAB" SortExpression="CAB" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="TeamName" HeaderText="Owner" SortExpression="TeamName" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ApplicationFunction" HeaderText="Function" SortExpression="ApplicationFunction" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ESXHostID" HeaderText="ESXHostID" SortExpression="ESXHostID"
Visible="False" />
<asp:BoundField DataField="ServerID" HeaderText="ServerID" InsertVisible="False"
ReadOnly="True" SortExpression="ServerID" Visible="False" />
</Columns>
<HeaderStyle Font-Bold="True" ForeColor="Black" />
</asp:GridView>

I do not want the first column (the asp:CommandField) and instead I want the Data ServerName to be the Select Item.

Is there a parameter to do that?

Thanks again.

Olivier
 
Thanks Oliver -- my mistake, I'm a bit behind re: VS 2005 and SQL - that was my initial thought - I see now what is going on. There are many here that work with SQL/GridView on a dailey basis and will drop in to help -- not familiar with this. My gut feeling is that you might set the commandfiled to visible=false and create some type of TemplateColumn to substitute. Hang in there; ca8msm, Jim et al. will drop by and give you their assessment. Good Luck!
 
Isadore is correct...

The only way I found to do that was to add this code in the HTML, if anyone knows of a better way, please share:

Code:
Text='<%# Eval("Your column") %>'

That goes in the linkbutton of the ItemTemplate.

Jim
 
Hi,
Thanks very much indeed both of you.
Your combined help was very useful.

Here is what I have done if someone has the same problem :

<asp:TemplateField HeaderText="Server Name" SortExpression="ServerName">
<HeaderStyle horizontalalign="Left" verticalalign="Middle"/>
<ItemStyle horizontalalign="Left" ForeColor="Black" Font-Bold="True"/>
<ItemTemplate>
<asp:HyperLink Text='<%# Eval("ServerName") %>' ID="Hyperlink1" runat="server" NavigateUrl='<%# "mypage.aspx?serverid=" + DataBinder.Eval(Container, "DataItem.ServerID")%>'/>
</ItemTemplate>
<ControlStyle ForeColor="Black" Width="100px" />
</asp:TemplateField>

It is looking exactly as the Select column but with the Item I wanted!

Thanks again.

Olivier :)

Note : I am coding in C# which explains the '+' rather than the '&'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top