Aspxgridview selected ve toplu işlemleri

--aşağıdaki kod bütün seçili rowlara işlem yapar
            List SelectedUsers = grid.GetSelectedFieldValues(new string[] { "ID", "TUTAR" });
            foreach (object user in SelectedUsers)
            {
                IList items = user as IList;
                if (items == null) return;
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=1, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
                cmd.ExecuteNonQuery();
            }




---aşağıdaki kod seçili seçili deil farketmez hepsine işlem yapar
            for (int i = 0; i < grid.VisibleRowCount; i++)
            {
                var items = grid.GetRowValues(i, new string[] { "ID", "TUTAR" }) as object[];
                // ASPxListBox1.Items.Add(rowValues[0].ToString());
                //you can add these key in a list here

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=2, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
                cmd.ExecuteNonQuery();

ASPXGRIDVIEW İşlemleri

Gridviewde seçili satırın bilgisini alabilme :
        protected void ASPxGridView1_SelectionChanged(object sender, EventArgs e)
        {
            var products = ASPxGridView1.GetSelectedFieldValues(“NAME”);
            Label1.Text = products[0].ToString();
        }

Gridviewin Sonuna İşlemler Seç eklemek için source da sona ekle
           
               
           
       
   

Gridview devexpress 7.2 sonrası için gecerli export Gridview
un altina ekle
 

un ustune ekle
        <Toolbars>
            <dx:GridViewToolbar EnableAdaptivity=“true”>
                <Items>
                    <dx:GridViewToolbarItem Command=“ExportToPdf” />
                    <dx:GridViewToolbarItem Command=“ExportToXls” />
                    <dx:GridViewToolbarItem Command=“ExportToXlsx” />
                    <dx:GridViewToolbarItem Command=“ExportToDocx” />
                    <dx:GridViewToolbarItem Command=“ExportToRtf” />
                    <dx:GridViewToolbarItem Command=“ExportToCsv” />
                </Items>
            </dx:GridViewToolbar>
        </Toolbars>


Gridview grup category combobox ve baglantisi 
birinci sqldatasource_musteriler yarat ve bunu aspxgridviewe bind
Ikinci datasource sqldatasource_musterigruplari  yarat  bu bir yere bind olmayacak

Sqlden iki tablo yarat birinin adi musteri(id,adi,grupid) olsun
digeride musteri_grup (id,grup_adi) olsun

aspxgridview designerda columnsa tikla combobox column ekle captionunu grup yap, Fieldname grupid sec, sag tabda comboboxpropertiesde datasourceid musteri_gruplarini sec text field grup_adi , valuefield=id 


Gridview Horizontal scrollbar 

   

       

       

       

Datasource eklemede hata alırsan sol taraftan server explorerden modify deyip save passwordu seç


Gridview  Required zorunlu alan ayari
Designerda ac ve columnsdan zorunlu alana tıkla ve sağda textboxpropertiesden en aşağıda validation settingste requiredi true yap

Master Detail Grid
ONCE 2 TANE SQLDATASOURCE VE 2 TANE ASPXGRIDVIEW YARAT BIRI MUSTERILER DIGERI MUSTERI HAREKETLER
MUSTERILERI NORMAL TABLODAN AL ASPXGRIDVIEW MUSTERILERIN SETTINGS DETAILDE DETAILROWU TRUE YAP,

MUSTERI HAREKETLERINIDE AL WHERE KISMINA TIKLA COLUMN MUSTERI_ID OPERATOR ” = ”  , SOURCE SESSION , SESSION FIELD = MUSTERI_ID

VE DAHA SONRA KODA EKLE
        protected void ASPxGridViewmusterihareketler_BeforePerformDataSelect(object sender, EventArgs e)
        {
            Session[“MUSTERI_ID”] = (sender as ASPxGridView).GetMasterRowKeyValue();
        }

SON OLARAKDA ASPXGRIDVIEWMUSTERILERE TIKLA EDITTEMPLATE VE DETAILROWU SEC VE ASPXGRIDMUSTERIHAREKETLERINI ICINE SURUKLE VE END TEMPLATE YAP


Gridviewda son kolumun genişliğini max yapmak
       
           
           
           
               
           
            <dx:GridViewDataTextColumn FieldName="ADI" VisibleIndex="2" Width=”100%”>
           
       


gridview detay masterda detay width sorunu once masterin altina ekle :
    <dx:ASPxGridView Width=”100%” 
       
       

sonra masterin son colomunun widthini %100 yap
 

sonra detaya ekle
   <dx:ASPxGridView2 Width=”100%” 
       
       

Devexpress gridview Dinamik Satır Ekleme (sil butonuyla)

Bir tane devexpress gridview yarat ve kodlar aşağıda

 

 

 
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TIPEXE
{
    public partial class Form1 : Form
    {
        public class BILGILER
        {

            public BILGILER()
            {
            }

            public string BARKOD { get; set; }
            public string ADI { get; set; }
            public string SİL { get; set; }

        }
        public BindingList _Grid_data;
        public Form1()
        {
            InitializeComponent();

        }
        private void button3_Click(object sender, EventArgs e)
        {
            _Grid_data.Add(new BILGILER()
            {
                BARKOD = "asd",
                ADI = "assaas"
            });
            RepositoryItemButtonEdit SILDUGMESI = new RepositoryItemButtonEdit();
            SILDUGMESI.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            SILDUGMESI.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
            SILDUGMESI.Buttons[0].Image = Bitmap.FromFile("resimler\\simgeler\\SIL.png");
            SILDUGMESI.Buttons[0].Caption = "SİL";
            SILDUGMESI.ButtonClick += SILDUGMESI_ButtonClick;
            gridControl1.RepositoryItems.Add(SILDUGMESI);
            gridView1.Columns["SİL"].ColumnEdit = SILDUGMESI;
        }
        private void SILDUGMESI_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            gridView1.DeleteSelectedRows();
        }
        private void bunifuFlatButton3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _Grid_data = new BindingList();
            gridControl1.DataSource = _Grid_data;
            gridView1.PopulateColumns();
            //bunifuFlatButton4.BackColor = Color.Teal;
            //bunifuFlatButton4.Activecolor = Color.Teal;
        }
    }
}

visual c# gridview with parameter

 private void button1_Click_3(object sender, EventArgs e)
        {
            string connectionString = null;
            SqlConnection cnn;
            connectionString = "Server = " + AYARLAR.txtServerc + "; Database = " + AYARLAR.txtVeritabanic + "; User Id = " + AYARLAR.txtKullanicic + "; Password = " + AYARLAR.txtParolac;




            FileInfo file = new FileInfo(Application.StartupPath + "\\SQL.txt");
            string script = file.OpenText().ReadToEnd();

            cnn = new SqlConnection(connectionString);

            SqlDataAdapter da = new SqlDataAdapter(script, cnn);
            da.SelectCommand.Parameters.AddWithValue("@tarih1", dateEdit1.Text);
            da.SelectCommand.Parameters.AddWithValue("@tarih2", dateEdit2.Text);
            DataTable dt = new DataTable();

            da.Fill(dt);
            gridControl1.DataSource = dt;
            gridView1.ExpandAllGroups();
            gridView1.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
            // Create and setup the first summary item.

            GridGroupSummaryItem item1 = new GridGroupSummaryItem();
            item1.FieldName = "Odeme Tutari";
            item1.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            item1.DisplayFormat = "Odeme Tutari {0:c2}";
            item1.ShowInGroupColumnFooter = gridView1.Columns["Odeme Tutari"];
            gridView1.GroupSummary.Add(item1);

            {
                //GridView RunTime Gruplama
                GridColumn Grupla = gridView1.Columns["Odeme Tipi"];

                gridView1.BeginSort();
                try
                {
                    gridView1.ClearGrouping();
                    Grupla.GroupIndex = 0;
                }
                finally
                {
                    gridView1.EndSort();
                }
                gridView1.ExpandAllGroups();
            }

            gridView1.Columns["Odeme Tutari"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            gridView1.Columns["Odeme Tutari"].SummaryItem.DisplayFormat = "Odeme Toplam = {0}";
            gridView1.BestFitColumns();
            gridView1.Columns["Odeme Tutari"].DisplayFormat.FormatType = FormatType.Numeric;
            gridView1.Columns["Odeme Tutari"].DisplayFormat.FormatString = "c2";

            gridView1.Columns["Iade Tutari"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            gridView1.Columns["Iade Tutari"].SummaryItem.DisplayFormat = "Iade Toplam = {0}";
            gridView1.BestFitColumns();
            gridView1.Columns["Iade Tutari"].DisplayFormat.FormatType = FormatType.Numeric;
            gridView1.Columns["Iade Tutari"].DisplayFormat.FormatString = "c2";

            gridView1.Columns["Odeme Tipi"].SortOrder = DevExpress.Data.ColumnSortOrder.Descending;

            gridView1.BestFitColumns();
        }

Devexpress gridview export customised header

using DevExpress.XtraPrinting;
using DevExpress.Printing.ExportHelpers;
using DevExpress.Export;

private void simpleButton1_Click(object sender, EventArgs e) {
// Ensure that the data-aware export mode is enabled.
DevExpress.Export.ExportSettings.DefaultExportType = ExportType.DataAware;
// Create a new object defining how a document is exported to the XLSX format.
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
// Subscribe to the CustomizeSheetHeader event.
options.CustomizeSheetHeader += options_CustomizeSheetHeader;
// Export the grid data to the XLSX format.
string file = "grid-export.xlsx";
gridControl.ExportToXlsx(file, options);
// Open the created document.
System.Diagnostics.Process.Start(file);
}

void options_CustomizeSheetHeader(DevExpress.Export.ContextEventArgs e) {
// Create a new row.
CellObject row = new CellObject();
// Specify row values.
row.Value = "The document is exported from the IssueList database.";
// Specify row formatting.
XlFormattingObject rowFormatting = new XlFormattingObject();
rowFormatting.Font = new XlCellFont { Bold = true, Size = 14 };
rowFormatting.Alignment = new DevExpress.Export.Xl.XlCellAlignment { HorizontalAlignment = DevExpress.Export.Xl.XlHorizontalAlignment.Center, VerticalAlignment = DevExpress.Export.Xl.XlVerticalAlignment.Top };
row.Formatting = rowFormatting;
// Add the created row to the output document.
e.ExportContext.AddRow(new [] {row});
// Add an empty row to the output document.
e.ExportContext.AddRow();
// Merge cells of two new rows.
e.ExportContext.MergeCells(new DevExpress.Export.Xl.XlCellRange(new DevExpress.Export.Xl.XlCellPosition(0, 0), new DevExpress.Export.Xl.XlCellPosition(5, 1)));
}

gridview connect to ms sql with txt file query and get data to gridview with summary

  string connectionString = null;
            SqlConnection cnn;
            connectionString = "Server = " + ondegerler.SQLBAGLANTISI_KAYNAK + "; Database = " + ondegerler.SQLBAGLANTISI_VERITABANI + "; User Id = " + ondegerler.SQLBAGLANTISI_KULLANICI + "; Password = " + ondegerler.SQLBAGLANTISI_PAROLA;
            FileInfo file = new FileInfo(Application.StartupPath + "\\tbl_cariler.txt");
            string script = file.OpenText().ReadToEnd();
            cnn = new SqlConnection(connectionString);
            SqlDataAdapter da = new SqlDataAdapter(script, cnn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            gridControl1.DataSource = dt;
            gridView1.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
            gridView1.Columns[1].SummaryItem.DisplayFormat = "Adet = {0}";

            gridView1.Columns["Bakiye"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            gridView1.Columns["Bakiye"].SummaryItem.DisplayFormat = "Toplam = {0}";
            gridView1.BestFitColumns();

Devexpress grid databar

            GridFormatRule gridFormatRule = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
            gridFormatRule.Column = gridView1.Columns[“Bakiye”];
            formatConditionRuleDataBar.PredefinedName = “Blue Gradient”;
            gridFormatRule.Rule = formatConditionRuleDataBar;
            this.gridView1.FormatRules.Add(gridFormatRule);

Devexpress gridview export to excel with savefiledialog

            string filename;
            saveFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.ShowDialog();
            filename = saveFileDialog1.FileName;
            if (filename == "") filename = "";
            else
            {
                gridView1.ExportToXlsx(filename);
                System.Diagnostics.Process.Start(filename);
            }

vs 2013 c# Devexpress gridview sağ tıklayarak excel dosyası olarak kaydet

Forma 1 adet contextMenuStrip1 ve 1 adet saveFileDialog1 at gridControl1de ki dataları excele kaydetmek için;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.OleDb;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;

contextMenuStrip1  tıkla Excele kaydet item yarat ve çift tıkla ve yaz;

            //excele kaydet
            string filename;
            saveFileDialog1.Filter = “xlsx files (*.xlsx)|*.xlsx”;
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.ShowDialog();
            filename = saveFileDialog1.FileName;
            if (filename == “”) filename = “”; else gridView1.ExportToXlsx(filename);

Daha sonra gridcontrola tıkla ve contextmenustripini contextMenuStrip1 olarak seç