Repeater da HyperLink Kullanımı

 

Merhaba arkadaşlar bu makalemizde Repeater da hyperlink nasıl kullanılacağını göstereceğiz. Hyperlinke tıkladığımızda DetailsView.aspx sayfasında seçili satırın detay bilgilerini göstereceğiz.



 

 

 

 

 

Şekil 1


 



Şekil 2


Default.aspx.cs

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

     

 

        if (!IsPostBack)

        {

            BindData();

          

        }

 

    }

 

    SqlConnection con;

    string constr;

    string sql;

    SqlCommand cmd;

    SqlDataAdapter da;

    DataSet ds;

 

 

    protected void BindData()

    {

 

        {

            constr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\kategori.mdf;Integrated Security=True";

            sql = "select * from [dbo].[Table]";

            con = new SqlConnection(constr);

            con.Open();

            cmd = new SqlCommand(sql, con);

            da = new SqlDataAdapter(cmd);

            ds = new DataSet();

            da.Fill(ds);

            con.Close();

 

            Repeater1.DataSource = ds;

            Repeater1.DataBind();

        }

    }

}

  

Default.aspx

 

 

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

 

<!DOCTYPE html>

 

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

<head runat="server">

    <title></title>

</head>

<body>

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

        <div>

            <asp:Repeater ID="Repeater1" runat="server" >

                <HeaderTemplate>

<table id="tblDetay" style="width:1000px; border-collapse: collapse; font-family:Tahoma; font-size:x-large;" border="1" cellpadding:"5" cellspacing:"0"  >

<tr style="background-color: #ff0000; height: 30px; color:#fff" align:"center">

<th>Id</th>

<th>Yazar</th>

<th>Kitap</th>

<th>Fiyat</th>

<th>Detay</th>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr >

<td style="width:auto;">

<%#Eval("id").ToString()%>

</td>

<td style="width: auto;" >

<%#Eval("yazar").ToString()%>

</td>

<td style="width: auto; ">

<%#Eval("kitap").ToString()%>

</td>

    <td >

<%#Eval("fiyat").ToString()%>

</td>

    <td style="width:auto;">

        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# string.Format("~/Details.aspx?Id={0}&Yazar={1}&Kitap={2}&Fiyat={3} ",

                HttpUtility.UrlEncode(Eval("Id").ToString()), HttpUtility.UrlEncode(Eval("Yazar").ToString()), HttpUtility.UrlEncode(Eval("Kitap").ToString()), HttpUtility.UrlEncode(Eval("Fiyat").ToString())) %>'

            Text="Detay için tiklayin!" />

 

 

    </td>

</tr>

</ItemTemplate>

<FooterTemplate>

</table>

</FooterTemplate>

            </asp:Repeater>

        </div>

    </form>

</body>

</html>

 

Details.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class Details : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            lblId.Text = HttpUtility.UrlDecode(Request.QueryString["Id"]);

            lblYazar.Text = HttpUtility.UrlDecode(Request.QueryString["Yazar"]);

            lblKitap.Text = HttpUtility.UrlDecode(Request.QueryString["Kitap"]);

            lblFiyat.Text = HttpUtility.UrlDecode(Request.QueryString["Fiyat"]);

        }

    }

 

}

 

Details.aspx

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

 

<!DOCTYPE html>

 

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

<head runat="server">

    <title></title>

</head>

<body>

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

        <div>

            <table style="font-style:italic; font-family:Tahoma; font-size:x-large">

               

                <tr>

                    <td>

                        <b>Id :</b>

                    </td>

                    <td>

                        <asp:Label ID="lblId" runat="server"></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td>

                        <b>Yazar :</b>

                    </td>

                    <td>

                        <asp:Label ID="lblYazar" runat="server"></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td>

                        <b>Kitap :</b>

                    </td>

                    <td>

                        <asp:Label ID="lblKitap" runat="server"></asp:Label>

                    </td>

 

                </tr>

                <tr>

                    <td>

                        <b>Fiyat :</b>

                    </td>

                    <td>

                        <asp:Label ID="lblFiyat" runat="server"></asp:Label>

                    </td>

                </tr>

 

            </table>

 

        </div>

    </form>

</body>

</html>

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN

About Bahadır Şahin

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Öne Çıkan Yayın

GridView da Seçili Satırı DetailsView da Göstermek

Merhaba arkadaşlar bu makalemizde GridView nesnesi ile birlikte DetailsView nesanesini birlikte kullanacağız. GridView da seçili satırın de...