Sıralama: Administration
Gruplar: Administrators
Katılan: 6.05.2014(UTC) Mesajlar: 670
19 Kere Teşekkür Etti. 152 Mesajına Toplam 253 Kere Teşekkür Edildi.
|
Originally Posted by: sabrisavas Hocam konu hakkinda yardimci olabilcekmisiniz. Kusara bakmayın ozel işlerden dolayı biraz cevap geçikti , Anladıgım kadarı ile sayfa üzerinden dinamik bir satır ekleyip aynı anda içeriye insert geçmek istiyorsunuz, Bunu yapmanız için runtime anında yeni textboxlar ekleyip onların idlerini bulup içeri insert etmeniz gerekmekte, Bunu for döngüsü ile yapmanız gerekmekte Aşağıdaki kod blogunun dinamik kontrol yazan fonksiyonunda bu işlemi yapıyorum database işlemleri enterprise library ile yapılmış Kod:
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class EditPlan : System.Web.UI.Page
{
string price;
string store;
DropDownList dp;
int LanguageSum;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["count"] = 1;
if (Request.QueryString["id"] == null)
{
}
else
{
DropDownListPlan.SelectedValue = Request.QueryString["id"].ToString();
}
}
LanguageCount();
}
protected override void OnLoad(EventArgs e)
{
price = TextBoxPrice.Text;
store = TextBoxStorage.Text;
base.OnLoad(e);
genarateDynamicControls();
}
private void genarateDynamicControls()
{
ViewState["control"] = "textbox";
createDynamicTextBox("TextBox");
}
private void createDynamicTextBox(string p)
{
//dp = new DropDownList();
//dp.ID = "DropDownListPlan";
//dp.AutoPostBack = true;
//Database objDatabaseFillPlan = DatabaseFactory.CreateDatabase();
//DataSet dsFillPlan = objDatabaseFillPlan.ExecuteDataSet(CommandType.Text, "SELECT PlanId FROM Plans");
//dp.DataSource = dsFillPlan;
//dp.DataValueField = "PlanId";
//dp.DataTextField = "PlanId";
//dp.DataBind();
//PlaceHolderDynamicContent.Controls.Add(dp);
//dp.SelectedIndexChanged += dynamicDDL_SelectedIndexChanged;
//DropDownListPlan.DataBind();
Session["deger"] = DropDownListPlan.SelectedValue;
Label lblName;
Label lblDesc;
Label lblLangName;
Label lblLangDesc;
TextBox txtPlanName;
TextBox txtPlanDesc;
for (int i = 1; i <= LanguageSum; i++)
{
//css kullanmak için
//lblName.CssClass = "CssClass";
lblName = new Label();
lblName.ID = "lblName" + i.ToString();
lblName.Text = "Plan Name";
lblDesc = new Label();
lblDesc.ID = "lblDesc" + i.ToString();
lblDesc.Text = "Plan Description";
lblLangName = new Label();
lblLangName.ID = "lblLang" + i.ToString();
lblLangDesc = new Label();
lblLangDesc.ID = "lblLangDesc" + i.ToString();
Database objDatabase = DatabaseFactory.CreateDatabase();
DataSet ds = new DataSet();
DataRow dRow;
try
{
ds = objDatabase.ExecuteDataSet("GetPortalLanguageDetail");
dRow = ds.Tables[0].Rows[i - 1];
lblLangName.Text = dRow.ItemArray.GetValue(1).ToString();
lblLangName.TabIndex = Convert.ToInt16(dRow.ItemArray.GetValue(0));
lblLangDesc.Text = dRow.ItemArray.GetValue(1).ToString();
}
catch (Exception exp)
{
LabelResult.Visible = true;
LabelResult.Text = exp.ToString();
}
txtPlanName = new TextBox();
txtPlanName.ID = "TxtPlanName" + i.ToString();
txtPlanDesc = new TextBox();
txtPlanDesc.ID = "TxtDescPlanDesc" + i.ToString();
//txtPlanDesc.Multiline = true;
txtPlanDesc.TextMode = TextBoxMode.MultiLine;
txtPlanDesc.Width = 200;
txtPlanDesc.Height = 100;
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("<table width=400><tr><td width=200>"));
PlaceHolderDynamicContent.Controls.Add(lblName);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("  ("));
PlaceHolderDynamicContent.Controls.Add(lblLangName);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl(")"));
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("</td><td width=200>"));
PlaceHolderDynamicContent.Controls.Add(txtPlanName);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("</td></tr>"));
//PlaceHolderDynamicContent.Controls.Add(new LiteralControl("<br/>"));
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolderDynamicContent.Controls.Add(lblDesc);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("  ("));
PlaceHolderDynamicContent.Controls.Add(lblLangDesc);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl(")"));
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolderDynamicContent.Controls.Add(txtPlanDesc);
PlaceHolderDynamicContent.Controls.Add(new LiteralControl("</td></tr></table>"));
DataTable dt = new DataTable();
Database objDatabasePlanValue = DatabaseFactory.CreateDatabase();
DbCommand cmd;
cmd = objDatabasePlanValue.GetStoredProcCommand("dbo.GetPlan");
if (Request.QueryString["id"] == null)
{
objDatabasePlanValue.AddInParameter(cmd, "@PlanId", DbType.Int32, 1);
}
else
{
objDatabasePlanValue.AddInParameter(cmd, "@PlanId", DbType.Int32, Convert.ToInt32(Request.QueryString["id"]));
}
dt = objDatabasePlanValue.ExecuteDataSet(cmd).Tables[0];
((TextBox)PlaceHolderDynamicContent.FindControl("TxtPlanName" + i.ToString())).Text = "";
((TextBox)PlaceHolderDynamicContent.FindControl("TxtPlanName" + i.ToString())).Text = dt.Rows[i - 1][0].ToString();
((TextBox)PlaceHolderDynamicContent.FindControl("TxtDescPlanDesc" + i.ToString())).Text = "";
((TextBox)PlaceHolderDynamicContent.FindControl("TxtDescPlanDesc" + i.ToString())).Text = dt.Rows[i - 1][1].ToString();
}
DataTable dtValu = new DataTable();
Database objDatabasePlan = DatabaseFactory.CreateDatabase();
DbCommand cmdPlan;
cmdPlan = objDatabasePlan.GetStoredProcCommand("dbo.GetPlanMaster");
if (Request.QueryString["id"] == null)
{
objDatabasePlan.AddInParameter(cmdPlan, "@PlanId", DbType.Int32, 1);
}
else
{
objDatabasePlan.AddInParameter(cmdPlan, "@PlanId", DbType.Int32, Convert.ToInt32(Request.QueryString["id"]));
}
dtValu = objDatabasePlan.ExecuteDataSet(cmdPlan).Tables[0];
TextBoxStorage.Text = dtValu.Rows[0][0].ToString();
TextBoxPrice.Text = dtValu.Rows[0][1].ToString();
}
public void LanguageCount()
{
Database objDatabase = DatabaseFactory.CreateDatabase();
DataSet ds = new DataSet();
DataRow dRow;
try
{
ds = objDatabase.ExecuteDataSet("GetPortalLanguageCount");
dRow = ds.Tables[0].Rows[0];
LanguageSum = Convert.ToInt32(dRow.ItemArray.GetValue(0));
}
catch (Exception ex)
{
}
}
protected void DropDownListPlan_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("EditPlan.aspx?id="+DropDownListPlan.SelectedValue);
}
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
UpdatePlans();
string txtName;
string txtDesc;
Int32 lblLangId;
for (int i = 1; i <= LanguageSum; i++)
{
Label langId = (Label)PlaceHolderDynamicContent.FindControl("lblLang" + i.ToString());
lblLangId = langId.TabIndex;
TextBox Name = (TextBox)PlaceHolderDynamicContent.FindControl("TxtPlanName" + i.ToString());
txtName = Name.Text;
TextBox Desc = (TextBox)PlaceHolderDynamicContent.FindControl("TxtDescPlanDesc" + i.ToString());
txtDesc = Desc.Text;
DataTable dt = new DataTable();
Database objDatabase = DatabaseFactory.CreateDatabase();
DbCommand cmd;
String PlanGlobalName = txtName;
String PlanGlobalDescripiton = txtDesc;
Int32 PortalLanguageId = lblLangId;
Int32 PlanId;
if (Request.QueryString["id"] == null)
{
PlanId = 1;
}
else
{
PlanId = Convert.ToInt32(Request.QueryString["id"]);
}
try
{
cmd = objDatabase.GetStoredProcCommand("UpdatePlanGlobal");
objDatabase.AddInParameter(cmd, "@PlanGlobalName", DbType.String, PlanGlobalName);
objDatabase.AddInParameter(cmd, "@PlanGlobalDescripiton", DbType.String, PlanGlobalDescripiton);
objDatabase.AddInParameter(cmd, "@PortalLanguageId", DbType.Int32, PortalLanguageId);
objDatabase.AddInParameter(cmd, "@PlanId", DbType.Int32, PlanId);
dt = objDatabase.ExecuteDataSet(cmd).Tables["PlanGlobal"];
}
catch (Exception exp)
{
LabelResult.Visible = true;
LabelResult.Text = exp.ToString();
}
}
Response.Redirect("EditPlan.aspx?id=" + DropDownListPlan.SelectedValue);
}
public void UpdatePlans()
{
DataTable dt = new DataTable();
Database objDatabase = DatabaseFactory.CreateDatabase();
DbCommand cmd;
Int32 PlanStorage = Convert.ToInt32(store);
Decimal PlanPrice = Convert.ToDecimal(price);
Int32 PlanId ;
if (Request.QueryString["id"] == null)
{
PlanId = 1;
}
else
{
PlanId = Convert.ToInt32(Request.QueryString["id"]);
}
cmd = objDatabase.GetStoredProcCommand("dbo.UpdatePlan");
objDatabase.AddInParameter(cmd, "@PlanStorage", DbType.Int32, PlanStorage);
objDatabase.AddInParameter(cmd, "@PlanPrice", DbType.Decimal, PlanPrice);
objDatabase.AddInParameter(cmd, "@PlanId", DbType.Decimal, PlanId);
dt = objDatabase.ExecuteDataSet(cmd).Tables["Plans"];
}
}
|
Sql Server 2016 Eğitimiz 19 Mayıs tarihinde başlayacaktır. 32 Saat Olup Ücret 1450 TL + KDV'dir. Kayıt ve ayrıntılar için tıklayınıztwitter.com/dbakademi Dua ve teşekkür en büyük servetlere bedel... |
mehmetzekikir: 1 Kişi mesajın için Teşekkür Etti.
|
|