asp.net - datagrid with several collimnas with links, and how to process the event of each link

1

How can I make an asp.net 2003 datagrid that has 6 columns (apart from the columns of the data) link in each of them, and what I am more lost: As a process each of the events of each link ? Thanks.

    
asked by RSillerico 07.07.2016 в 20:11
source

1 answer

0

To create additional columns you should only define them in the design

Creating Custom Columns for the ASP.NET Datagrid

I imagine in your grid you define the property AutoGenerateColumns in true. As you will notice in the article there are several ways to achieve it

You could define a columns of type HyperLinkColumn

<asp:DataGrid id="DataGrid1" 
   runat="server"
   AutoGenerateColumns="true">
   <Columns>
      <asp:HyperLinkColumn DataNavigateUrlField="application_id" 
          DataNavigateUrlFormatString="applicationform.aspx?id={0}" 
          DataTextField="application_id" HeaderText="APPLICATION_ID"></asp:HyperLinkColumn>
   </Columns>
</asp:DataGrid>

In this case it would be a link in the column that redirects to a url, the property DataNavigateUrlField

is important

Another alternative would be using <asp:ButtonColumn> .

<asp:DataGrid id="DataGrid1" 
   runat="server"
   AutoGenerateColumns="true">
   <Columns>
        <asp:ButtonColumn 
         HeaderText="Edit item" 
         ButtonType="LinkButton" 
         Text="Edit" 
         CommandName="Edit"/> 
   </Columns>
</asp:DataGrid>

You can define several ButtonColumn as you need

The action is received in the event ItemCommand where you will have the CommandName to know what action was hit

Just what I would advise is that if you want to give a specific position to these columns you define them all in design time and assign the AutoGenerateColumns="false"

    
answered by 07.07.2016 / 21:00
source