🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / gridview filtrelen row satırları modele atma filter to datasource

1-) C# RMOS - gridview filtrelen row satırları modele atma filter to datasource

 

public List<T> GetFilteredData<T>(ColumnView view)

        {

            List<T> resp = new List<T>();

            for (int i = 0; i < view.DataRowCount; i++)

                resp.Add((T)view.GetRow(i));

 

            return resp;

        }

 

 

** KULLANIMI USE **

 

private void btnDuzeltilenleriGonder_Click(object sender, EventArgs e)

        {

            ColumnView View = gridControl1.MainView as ColumnView;

            List<ConsentList> mydata = GetFilteredData<ConsentList>(View).ToList();

            MessageBox.Show("işlem tamam");

        }

       

 

** 2-) DATATABLE TO JSON YAPIP SONRA MODELE CAST ETMEK **

 

string jsonInfo = JsonConvert.SerializeObject(gridControlTeknikBilgiler.DataSource as DataTable);

 

 

 

** 3-) DATATABLE TO JSON YAPIP SONRA MODELE CAST ETMEK **

 

kaynak : https://stackoverflow.com/questions/39384606/get-filtered-rows-from-devexpress-gridview-c-sharp

 

 

 string json = DataTableToJsonObj(gridControlKampa.DataSource as DataTable);

 List<GenelModel> errorList = JsonConvert.DeserializeObject<List<GenelModel>>(json);

 

public string DataTableToJsonObj(DataTable dt)

        {

            DataSet ds = new DataSet();

            ds.Merge(dt);

            StringBuilder JsonString = new StringBuilder();

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

                JsonString.Append("[");

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

                {

                    JsonString.Append("{");

                    for (int j = 0; j < ds.Tables[0].Columns.Count; j++)

                    {

                        if (j < ds.Tables[0].Columns.Count - 1)

                        {

                            JsonString.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\",");

                        }

                        else if (j == ds.Tables[0].Columns.Count - 1)

                        {

                            JsonString.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\"");

                        }

                    }

                    if (i == ds.Tables[0].Rows.Count - 1)

                    {

                        JsonString.Append("}");

                    }

                    else

                    {

                        JsonString.Append("},");

                    }

                }

                JsonString.Append("]");

                return JsonString.ToString();

            }

            else

            {

                return null;

            }

        }

 2022 Temmuz 03 Pazar
 410