Forum

GridView de sorunum...
 
Bildirimler
Hepsini Temizle

GridView de sorunumvar kodlarıma ekleme yapabilirmisiniz? (AutoSort = True çalışmıyor)

5 Yazılar
2 Üyeler
0 Likes
446 Görüntüleme
(@TanerHAKYEMEZ)
Gönderiler: 3
Active Member
Konu başlatıcı
 

Merhaba

GridView ile veri tabanından verileri çekiyorum çektiğim müşterilerin ismini alfabatik sıralayamıyorum

GridView in AutoSort özelliğini True yapıyorum sonra istediğim bölümün
class ına SortExpression="KategoriAdi" tanımlıyorum çalıştırdığımda
çalılşıyormuş gibi oluyor ama hiç bir işlem yapmıyor.

sebebi ne olabilir? ne yapmam lazım

kodlarıma ekleme yapabilirmisiniz

  3 gündür uğraşıyorum araştırıyorum ama yapamadım.

 

aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/adminmaster.master" AutoEventWireup="true" CodeFile="Musterilerilistele.aspx.cs" Inherits="Admin_Musterilerilistele" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table border="1" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <th class="style6" height="41" scope="col" 
                style="color: #0066FF; text-align: left; background-color: #66CCFF">
                &nbsp;&nbsp; Müşteri Listesi</th>
        </tr>
        <tr>
            <td height="25">
                <table border="1" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <th class="style3" scope="col" width="20%">
                            Müşteri Adı Soyadı</th>
                        <th class="style3" scope="col" width="20%">
                            Kategorisi</th>
                        <th class="style3" scope="col" width="20%">
                            Firma Adı</th>
                        <th class="style3" scope="col" width="20%">
                            Cep Telefonu</th>
                        <th class="style3" scope="col" width="20%">
                            İlan</th>
                        <th class="style3" scope="col" width="20%">
                            Yer Göster</th>
                        <th class="style3" scope="col" width="20%">
                            <img border="0" src="Images/edit.png" /></th>
                        <th class="style3" scope="col" width="20%">
                            <img border="0" src="../images/sil.png" /></th>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="dlMusteriler" runat="server" AutoGenerateColumns="False" 
                    CellPadding="4" ForeColor="#333333" GridLines="None" 
                    onrowcommand="dlMusteriler_RowCommand" Width="100%" AllowSorting="True">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                         <asp:BoundField HeaderStyle-HorizontalAlign="Left" DataField="MusteriAdiSoyadi" HeaderText="MusteriAdiSoyadi" 
                            SortExpression="MusteriAdiSoyadi" >
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                     
                        <asp:BoundField DataField="MusteriAdiSoyadi" HeaderText="Müşteri adı" />
                        <asp:BoundField DataField="FirmaAdi" HeaderText="Firma Adı" />
                        <asp:BoundField DataField="Cep" HeaderText="Cep Telefonu" />
                        <asp:BoundField DataField="MusteriAdminAD" HeaderText="Muşteri Sorumlusu" />
                        <asp:BoundField DataField="FirmaAdi" HeaderText="Firma Adı" />
                        <asp:HyperLinkField DataNavigateUrlFields="MusteriId" 
                            DataNavigateUrlFormatString="musteriiLanGoster.aspx?id={0}" 
                            DataTextField="HaberSayisi" HeaderText="H.Sayısı" />
                        <asp:HyperLinkField DataNavigateUrlFields="MusteriId" 
                            DataNavigateUrlFormatString="musteriHaberGoster.aspx?id={0}" 
                            DataTextField="yerGostermeSayisi" HeaderText="Yer.Sayısı" />
                        <asp:HyperLinkField DataNavigateUrlFields="MusteriId" 
                            DataNavigateUrlFormatString="MusteriGuncelle.aspx?id={0}" 
                            DataTextField="MusteriId" HeaderText="Düzenle" />
                        <asp:TemplateField HeaderText="Sil">
                            <ItemTemplate>
                                <asp:LinkButton ID="linkbuton" runat="server" 
                                    CommandArgument='<%#Eval("MusteriId") %>' Text="Sil"> </asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#7C6F57" />
                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#E3EAEB" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F8FAFA" />
                    <SortedAscendingHeaderStyle BackColor="#246B61" />
                    <SortedDescendingCellStyle BackColor="#D4DFE1" />
                    <SortedDescendingHeaderStyle BackColor="#15524A" />
                </asp:GridView>
          
            </td>
        </tr>
    </table>
</asp:Content>

aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Musterilerilistele : System.Web.UI.Page
{

    public static string KategoriId = "";
    Fonksiyon system = new Fonksiyon();
    string islem = "";
    string MusteriId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminId"] == null)
        {
            Response.Redirect("Login.aspx");
        }

        KategoriId = Request.QueryString["KategoriId"];
        islem = Request.QueryString["islem"];
        MusteriId = Request.QueryString["MusteriId"];

        if (islem == "Sil")
        {
            system.cmd("Delete from Musteriler Where MusteriId=" + MusteriId);
            Response.Redirect("Musteriler.aspx");
        }

        DataTable dtMusteriler = system.GetDataTable("exec mustericek");
        dlMusteriler.DataSource = dtMusteriler;
        dlMusteriler.DataBind();


    }
    protected void dlMusteriler_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        Response.Redirect("Musterilerilistele.aspx");
        system.cmd("Delete from Musteriler Where MusteriId=16");
        // Response.Redirect("Musteriler.aspx");

    }
  
}
 
Gönderildi : 05/03/2014 23:12

(@BurakSenturk)
Gönderiler: 70
Trusted Member
 

Selam,

 

CodeBehind da datatable üzerinden sortexpression yapsanız daha kolay olmaz mı ? Ya da bu yapıyı istememenizin özel bir nedeni var mı?

 Örn :  DataTable.Select ( filterexpression, sortexpression);

İyi Çalışmalar Dilerim,

 
Gönderildi : 06/03/2014 13:57

(@TanerHAKYEMEZ)
Gönderiler: 3
Active Member
Konu başlatıcı
 

nasıl hocam

ben  yanlış yapıyorum

sanırım

rica etsem siz kodlarıma ekleme yapabilirmisiniz?

 
Gönderildi : 06/03/2014 23:02

(@BurakSenturk)
Gönderiler: 70
Trusted Member
 

Selamlar,

DataTable dtMusteriler = system.GetDataTable("exec mustericek");

dlMusteriler.DataSource = dtMusteriler;
dlMusteriler.DataBind();

 kodunun bu kısmına şöyle bir eklenti yapabilirsin ;

 DataRow[] Satirlar ;

string sartlar = "";

string siralama = "MusteriAdiSoyadi ASC";

Satirlar =  dtMusteriler.Select(sartlar, siralama);

dlMusteriler.DataSource = Satirlar;

dlMusteriler.DataBind(); 

 

Tabi bu yazdığımın farklı farklı bir dünya yolu var. Onlardan biride bu.

 

İyi Çalışmalar Dilerim, 

 
Gönderildi : 08/03/2014 17:25

(@TanerHAKYEMEZ)
Gönderiler: 3
Active Member
Konu başlatıcı
 

dediğiniz gibi yaptığımda

Server Error in '/' Application.


A field or property with the name 'MusteriAdiSoyadi' was not found on the selected data source.

Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.

Exception Details: System.Web.HttpException: A field or property with the name 'MusteriAdiSoyadi' was not found on the selected data source.

Source Error:

Line 38:         Satirlar = dtMusteriler.Select(sartlar, siralama);
Line 39:         dlMusteriler.DataSource = Satirlar;
Line 40:         dlMusteriler.DataBind(); 
Line 41: 
Line 42:  

 

hatasını veriyor

rica etsem kodlarıma ekleme yapabilirmisiniz hala sorunu halledemedim

 
Gönderildi : 27/03/2014 23:40

Paylaş: