aadi patel

aadi patel

  • NA
  • 53
  • 33.4k

Runtime generate HyperlinkField in Gridview

Nov 27 2012 2:31 AM
I have gridview in my website.
I want to add multiple parameters in sqldatasource.
Passed parameters will be changed according to user selection.
So i want to add data in gridview using code and add HyperlinkField runtime.

How To assign Hyperlink field in Grid-view run time using code behind?

This is code for gridview and sqldata source,

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EMP_ID" DataSourceID="SqlDataSource1" CssClass="Gridview">

<Columns> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
 <asp:BoundField DataField="SUBJECT" HeaderText="SUBJECT" SortExpression="SUBJECT" />

<asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="DisplayD.aspx?id={0}" DataTextField="MESSAGE" HeaderText="MESSAGE" />

<asp:BoundField DataField="DATE" HeaderText="DATE" SortExpression="DATE" ReadOnly="True" />
</Columns>
<SelectedRowStyle ForeColor="HotPink" BackColor="Snow" />
</asp:GridView>


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EAR_CS %>"
SelectCommand="LIST" SelectCommandType="StoredProcedure">
 <SelectParameters>
 <asp:SessionParameter Name="ID" SessionField="UserID" Type="Int32" />       </SelectParameters>
</asp:SqlDataSource>


Answers (1)