Yazı Font Küçült Yazı Font Büyült

GridView de HyperLink Kullanımı


Merhaba arkadaşlar, ilk önce Gridview nesnemize HyperLinkField alanı ekleyeceğiz.

 

Resim1

Şekil 1

GridView Tasks den Add New Column dan HyperLinkField alanını seçip, gerekli parametreleri giriyoruz (Şekil2).  

 

Resim2

Şekil 2

 

Daha sonra Detay.aspx sayfasına id no ya göre link vereceğiz.

Şekil 3 te görüldüğü gibi Detay linkine tıklanıldığında, ilgili personele ait detay bilgilerini Detay.aspx sayfasında göstermiş olacağız (Şekil 4).

 

Resim3

Şekil 3

 

Resim4

Şekil 4

 

Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

            CellPadding="4" DataKeyNames="id" DataSourceID="AccessDataSource1"

            ForeColor="#333333" GridLines="None">

            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

            <Columns>

                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"

                    ReadOnly="True" SortExpression="id" />

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

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

                <asp:HyperLinkField DataNavigateUrlFields="id"

                    DataNavigateUrlFormatString="Detay.aspx?id={0}" DataTextField="id"

                    DataTextFormatString="Detay" HeaderText="Detay" />

            </Columns>

            <EditRowStyle BackColor="#999999" />

            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

            <SortedAscendingCellStyle BackColor="#E9E7E2" />

            <SortedAscendingHeaderStyle BackColor="#506C8C" />

            <SortedDescendingCellStyle BackColor="#FFFDF8" />

            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />

        </asp:GridView>

   

    </div>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server"

        DataFile="~/App_Data/bilgi.accdb"

        SelectCommand="SELECT [id], [Ad], [Soyad] FROM [PersonelListesi]">

    </asp:AccessDataSource>

    </form>

</body>

</html>

 

 

Detay.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Detay.aspx.cs" Inherits="Detay" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1"

            CellPadding="4" ForeColor="#333333" GridLines="None">

            <AlternatingRowStyle BackColor="White" />

            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />

            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />

            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />

            <SortedAscendingCellStyle BackColor="#FDF5AC" />

            <SortedAscendingHeaderStyle BackColor="#4D0000" />

            <SortedDescendingCellStyle BackColor="#FCF6C0" />

            <SortedDescendingHeaderStyle BackColor="#820000" />

        </asp:GridView>

        <br />

        <asp:AccessDataSource ID="AccessDataSource1" runat="server"

            DataFile="~/App_Data/bilgi.accdb"

            SelectCommand="SELECT [id], [Ad], [Soyad], [Birim], [Telefon], [Mail] FROM [PersonelListesi] WHERE id=@id">

            <SelectParameters>

               <asp:QueryStringParameter Name="id" QueryStringField="id" />

            </SelectParameters>

        </asp:AccessDataSource>

   

    </div>

    </form>

</body>

</html>

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN