Domanda

I want to publish two types of information on same column in ASP grid view.

<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

<asp:hyperlinkfield text="Detail" datanavigateurlfields="name" datanavigateurlformatstring="LeadInformation.aspx?name={0}" />

The first column is a BoundField and second one is hyperlinkField. These two types of information will display separately on two columns. or else I can do like this.

<asp:HyperLinkField DataNavigateUrlFields="name" DataNavigateUrlFormatString="LeadInformation.aspx?name={0}" DataTextField="name" HeaderText="User Name" SortExpression="name" />

Then it will display all information on one column as a hyperlink.

I just want to display name as it is. (not as a hyperlink). And in same column,add a hyperlink like above.

Please help me.

È stato utile?

Soluzione

Make it a TemplateField. Then add a Label and a Hyperlink. Then for the Text of the Label and the NavigateURL for the hyperlink use Bind("ColumnName"). (or on the design mode right click and select Databindings and enter Bind("ColumnName") for the properties.

You can refer the below MSDN link which explains how to show two values in a single column (FirstName and LastName in this case)

MSDN

Altri suggerimenti

The answer is absolutely correct. A template field allows you to display anything you like in a gridview, rather than the standard ASP:NET gridview column controls. The price you pay is that it then becomes a bit harder to get access to the values in the controls. You will find it's often useful to use the CommandName and CommandArgument properties to get at values of the controls.

You have a fair learning curve ahead of you, I'm afraid, and certainly the question is too broad to be answered here. Try this article, or searching for "ASP.NET gridview templatefield".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top