Click here to Skip to main content
16,021,293 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am working with Asp.Net.

Question: There are 2 tables in my database. First table is EmpMaster(EmpId,EmpName,Desig) and the second table is EmpAddress(EmpName,Address). So I used One GridView control in my default1.aspx page to bind the EmpMasater table data. Here the EmpName column is the hyperlink. When we click on the row of a EmpName column it takes us to other page default2.aspx there the second table is bound to another gridview control.
The code I have written in the source file is

XML
<columns>
  <asp:BoundField DataField="EmpId" HeaderText="EmpId" SortExpression="EmpId" />
  <asp:BoundField DataField="EmpName" HeaderText="EmpName" SortExpression="EmpName"/> 
  <asp:BoundField DataField="Desg" HeaderText="Desg" SortExpression="Desg" />
  <asp:HyperLinkField DataTextField="EmpName" NavigateUrl="~/Default2.aspx"/>
</columns>


Problem here is when I run the default1.aspx it show 4 columns.
EmpId  EmpName   Desg   EmpName
--------------------------------

But I don't want the EmpName hyperlink as the extra column. I want it in the Second column only.
Can anyone please give the solution for this.
Posted
Updated 20-Jun-11 3:03am
v2
Comments
strogg 20-Jun-11 9:08am    
Just figure it out genius!
Take off the <asp:HyperLinkField ... column
Or if you want the hyperlink in the second col, just delete the second <<asp:BoundField & move the hyperlink column up where you want

1 solution

It's very simple. You have used 3 BoundField Columns and a HyperLinkField Column and so the total columns that are displayed is 4.

But I don't want the EmpName hyperlink as the extra column. I want it in the Second column only.
Delete the second column and move the HyperLinkField Column to the second position and you are done.
XML
<columns>
  <asp:BoundField DataField="EmpId" HeaderText="EmpId" SortExpression="EmpId" />
  <asp:HyperLinkField DataTextField="EmpName" NavigateUrl="~/Default2.aspx"/>
  <asp:BoundField DataField="Desg" HeaderText="Desg" SortExpression="Desg" />
</columns>


Hope this helps!
 
Share this answer
 
Comments
Rajjjjjjj 20-Jun-11 10:18am    
Yeah... It's very simple.... Thanks Ankur thanks alot.
thatraja 20-Jun-11 11:28am    
Spot on, 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900