0
嗨我是新的使用telerik rad控制asp開發,我需要一些幫助。我有一個radGrid,當按下按鈕時會填充數據,我在論壇中找到了一個解決方案,用於選擇一行radGrid並獲取每個單元格的值,但現在我想知道如何將這些值保存到我的數據庫使用實體框架。我一直在嘗試將值放入字符串,然後在我的保存方法中調用字符串,但是當我執行程序時,我添加了兩個斷點,一個放在選擇行的方法中,並將值和其他值保存方法,當看到第一個方法中的斷點結果時,它將選中的行的值作爲每個字符串包含與radGrid中的單元格對應的數據,但在我的保存方法中字符串顯示爲空,如何解決此問題問題? 希望你能幫助我。 這裏是我的兩種方法來選擇和保存將數據從telerik radgrid保存到數據庫
protected void RgSolic_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridDataItem selectedItem in rgSolic.SelectedItems)
{
strNom = selectedItem["NombreCompleto"].Text;
strPuesto = selectedItem["nom_pue"].Text;
strCveAdscripcion = selectedItem["cve_adscripcion"].Text;
strArea = selectedItem["nom_area"].Text;
}
}
protected void btnRegistra_Click(object sender, EventArgs e)
{
//BD_SSEGUAEntities sseguaRegistro = new BD_SSEGUAEntities();
//sseguaRegistro.spRegistraSolicitud1();
//Valida Datos del Menor
using (var dbContext = new BD_SSEGUAEntities())
{
var ResultSet = new Menor();
var ResultSol = new Solicitud();
var ResulBitacora = new Bitacora();
if (chkMasc.Checked)
{
sexo = "M";
}
if (chkFem.Checked)
{
sexo = "F";
}
if (rdTxtAPatMen.Text != "" && rdTxtAMatMen.Text != "" && rdTxtNomMen.Text != "" && RadDatePicker1.SelectedDate != null && sexo != "" && rdCmbEdificio.SelectedValue != "" && rdTxtDomicilio.Text != "" && rdTxtHEnt.Text != "" && rdTxtHSal.Text != "" && rdTxtTelOfic.Text != "" && rdTxtExt.Text != "" && rdTxtPart.Text != "" && rdTxtCorreoE.Text != "" && rdTxtDomPart.Text != "" && rdTxtNHijos.Text != "" && rdCmbTEmbzo.SelectedValue != "0")
{
try
{
System.DateTime.Now.Year.ToString();
//ResultSol.fcCvePuesto = rgSolic.Columns.FindByUniqueName("nom_pue").ToString();
//ResultSol.fcCveAdsc = rgSolic.Columns.FindByDataField("cve_adscripcion").ToString();
ResultSol.fcNomEmpleado = strNom;
ResultSol.fcCveAdsc = strCveAdscripcion;
ResultSol.fcCvePuesto = strPuesto;
ResultSol.fcDomLabora = rdTxtDomicilio.Text;
ResultSol.fiHorEntLab = (Byte)rdTxtHEnt.Value;
ResultSol.fiHorSalLab = (Byte)rdTxtHSal.Value;
ResultSol.fiTelOfna = rdTxtTelOfic.Text;
ResultSol.fiExtTel = rdTxtExt.Text;
ResultSol.fiTelPart = rdTxtPart.Text;
ResultSol.fcCorreoE = rdTxtCorreoE.Text;
ResultSol.fcDomPart = rdTxtDomPart.Text;
ResultSol.fiNumHijos = (Byte)rdTxtNHijos.Value;
foreach (var menor in listaMenores)
{
ResultSol.Menor.Add(menor);
}
dbContext.AddToSolicitud(ResultSol);
dbContext.SaveChanges();
//ResultSet.fcPatMenor = rdTxtAPatMen.Text;
//ResultSet.fcMatMenor = rdTxtAMatMen.Text;
//ResultSet.fcNomMenor = rdTxtNomMen.Text;
//ResultSet.fdFchNacMenor = (DateTime)RadDatePicker1.SelectedDate;
//ResultSet.fiAnosMenor = (Byte)rdTxtAnio.Value;
//ResultSet.fiMesesMenor = (Byte)rdTxtMeses.Value;
//ResultSet.fiSexoMenor = sexo;
//ResultSet.fdFchRegMenor = DateTime.Today;
//dbContext.Menores.AddObject(ResultSet);
//dbContext.SaveChanges();
//RgMenor.DataSource = ResultSet;
//RgMenor.Rebind();
}
catch (Exception ex)
{
Alerta(ex.Message);
}
}
else
{
Alerta("Captura todos lo datos del Menor");
}
}
}