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

QueryString Metodu Ile DetailsView da Gösterim

Merhaba arkadaslar bu makalemizde QueryString metodunu kullanarak DetailsView nesnesinde id no ya göre verilerimiz gösterecegiz. Default.aspx sayfamizda ki hyperlink nesnesinin NavigateUrl sini asagidaki gibi yapiyoruz.

HyperLink1.NavigateUrl = "~/Details.aspx?Id=2";

Bu sekilde hyperlink e tiklanildiginda Details.aspx sayfasina gidiyoruz ve Id degerini 2 olarak tasiyoruz.

Details.aspx sayfasinda asagidaki gibi QueryString metoduyla;

id = Convert.ToInt32(Request.QueryString["Id"]);

Id degerini id degiskenine atiyoruz ve bu degere göre sql sorgulamamizi yaparak, DetailsView da Id degerine göre gösterimi sagliyoruz.

 

Resim1

Sekil 1

 

Resim2

Sekil 2

 

Default.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 _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        HyperLink1.Text = "Detay için tiklayin.";

        HyperLink1.NavigateUrl = "~/Details.aspx?Id=2";

 

    }

}

 

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:HyperLink ID="HyperLink1" runat="server" Font-Names="Tahoma" Font-Size="Large">HyperLink</asp:HyperLink>

        </div>

    </form>

</body>

</html>

 

Details.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;

using System.IO;

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

{

    SqlConnection con;

    string constr;

    string sql;

    SqlCommand cmd;

    SqlDataAdapter da;

    DataSet ds;

   int id;

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

          

            BindData();

        }

     

    }

  

    protected void BindData()

    {

 

        {

            id = Convert.ToInt32(Request.QueryString["Id"]);

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

            sql = "select * from [dbo].[Table]Where Id=" + id;

            con = new SqlConnection(constr);

            con.Open();

            cmd = new SqlCommand(sql, con);

            da = new SqlDataAdapter(cmd);

            ds = new DataSet();

            da.Fill(ds);

            con.Close();

          

            DetailsView1.DataSource = ds;

            DetailsView1.DataBind();

        }

    }

}

 

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>

            <asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4" Font-Names="Tahoma" Font-Size="Large" ForeColor="#333333" GridLines="None" Height="133px" Width="279px">

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

                <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />

                <EditRowStyle BackColor="#999999" />

                <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />

                <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" />

            </asp:DetailsView>

        </div>

    </form>

</body>

</html>

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüsmek üzere. Bahadir SAHIN