Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am binding data to a gridview using a stored procedure as my datasource. The columns are arranged based on a parameter passed to the stored procedure so I'm not able to hardcode the column names in the grid. I also need all columns to be hyperlinked. When I add the hyperlinked column on page load, the hyperlinked column is added plus the column from the datasource is added. How can I modify the column from the datasource to be hyperlinked (using template or hyperlinkedfield) keeping in mind that the column name is unknown when data is binded?

<asp:HyperLinkField DataTextField="CANU" HeaderText="CAN-U" 
                 DataNavigateUrlFields="Model"   NavigateUrl="BBDetail.aspx" 
                    DataNavigateUrlFormatString="BBDetail.aspx?Model={0}&Region=CAN"
                    SortExpression="CANU" Target="_Blank" >
                <HeaderStyle Width="65px" />
                <itemstyle cssclass="HyperStyle" horizontalalign="Center" width="65px" />


Example of data coming from stored procedure (@col(?) = to ColumnName):
Exec ('Select Model, ['+@col1+'] as ['+@col1+'] , ['+@col2+'] as ['+@col2+'] , ['+@col3+'] as ['+@col3+'], ['+@col4+'] as ['+@col4+'], ['+@col5+'] as ['+@col5+'], ['+@col6+'] as ['+@col6+'] from PVTBOATSBUILT')
Posted
Updated 30-Nov-11 4:51am
v3
Comments
Michael Dela Cuesta 1-Dec-11 21:34pm    
I don't quite get it? how do you decide which column is to be hyperlinked when its name is unknown?
Michael Dela Cuesta 1-Dec-11 21:35pm    
By the way, "When I add the hyperlinked column on page load, the hyperlinked column is added plus the column from the datasource is added." <-- this happens since you haven't set AutoGenerateColumns to false, by default its true

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