mamadco
چهارشنبه 30 مهر 1393, 15:28 عصر
سلام دوستان من میخوام بدونم روشی که الان من دارم با asp.net کار میکنم چی هست و. منابع فارسی یا انگلیسیش کجاس چون من تو نت پیدا نمیکنم
نمونه کد پشته :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication13
{
public partial class WebForm1 : System.Web.UI.Page
{
MywebsiteEntities context = new MywebsiteEntities();
protected void Page_Load(object sender, EventArgs e)
{
lbltime.Text = (DateTime.Now).ToString();
}
protected void btnadd_Click(object sender, EventArgs e)
{
lbltime.Text = (DateTime.Now).ToString();
if (ViewState["myviewstate"] == null)
{
T_NewsGroup mynews = new T_NewsGroup
{
GroupTitle = txtgrouptitle.Text,
GroupLast = txtlastname.Text,
Grouptell = txttell.Text,
Groupcity = txtcity.Text,
GroupTime = lbltime.Text,
};
context.T_NewsGroup.Add(mynews);
context.SaveChanges();
gvgrouptitle.DataBind();
txtgrouptitle.Text="";
txtlastname.Text = "";
txttell.Text = "";
txtcity.Text = "";
}
else
{
int id = int.Parse(ViewState["myviewstate"].ToString());
var stredit = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
stredit.GroupTitle = txtgrouptitle.Text;
stredit.GroupLast = txtlastname.Text;
stredit.Grouptell = txttell.Text;
stredit.Groupcity = txtcity.Text;
context.SaveChanges();
gvgrouptitle.DataBind();
txtgrouptitle.Text = "";
txtlastname.Text = "";
txttell.Text = "";
txtcity.Text = "";
ViewState["myviewstate"] = null;
}
}
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
}
protected void gvgrouptitle_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "doEdit":
{
int id = int.Parse(e.CommandArgument.ToString());
var stredit = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
txtgrouptitle.Text = stredit.GroupTitle;
txtlastname.Text = stredit.GroupLast;
txttell.Text = stredit.Grouptell;
txtcity.Text = stredit.Groupcity;
context.SaveChanges();
gvgrouptitle.DataBind();
ViewState["myviewstate"] = id;
break;
}
case "doDelete":
{
int id = int.Parse(e.CommandArgument.ToString());
var strdel = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
context.T_NewsGroup.Remove(strdel);
context.SaveChanges();
gvgrouptitle.DataBind();
break;
}
}
}
}
}
نمونه کد پشته :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication13
{
public partial class WebForm1 : System.Web.UI.Page
{
MywebsiteEntities context = new MywebsiteEntities();
protected void Page_Load(object sender, EventArgs e)
{
lbltime.Text = (DateTime.Now).ToString();
}
protected void btnadd_Click(object sender, EventArgs e)
{
lbltime.Text = (DateTime.Now).ToString();
if (ViewState["myviewstate"] == null)
{
T_NewsGroup mynews = new T_NewsGroup
{
GroupTitle = txtgrouptitle.Text,
GroupLast = txtlastname.Text,
Grouptell = txttell.Text,
Groupcity = txtcity.Text,
GroupTime = lbltime.Text,
};
context.T_NewsGroup.Add(mynews);
context.SaveChanges();
gvgrouptitle.DataBind();
txtgrouptitle.Text="";
txtlastname.Text = "";
txttell.Text = "";
txtcity.Text = "";
}
else
{
int id = int.Parse(ViewState["myviewstate"].ToString());
var stredit = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
stredit.GroupTitle = txtgrouptitle.Text;
stredit.GroupLast = txtlastname.Text;
stredit.Grouptell = txttell.Text;
stredit.Groupcity = txtcity.Text;
context.SaveChanges();
gvgrouptitle.DataBind();
txtgrouptitle.Text = "";
txtlastname.Text = "";
txttell.Text = "";
txtcity.Text = "";
ViewState["myviewstate"] = null;
}
}
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
}
protected void gvgrouptitle_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "doEdit":
{
int id = int.Parse(e.CommandArgument.ToString());
var stredit = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
txtgrouptitle.Text = stredit.GroupTitle;
txtlastname.Text = stredit.GroupLast;
txttell.Text = stredit.Grouptell;
txtcity.Text = stredit.Groupcity;
context.SaveChanges();
gvgrouptitle.DataBind();
ViewState["myviewstate"] = id;
break;
}
case "doDelete":
{
int id = int.Parse(e.CommandArgument.ToString());
var strdel = (from n in context.T_NewsGroup where n.GroupID == id select n).First();
context.T_NewsGroup.Remove(strdel);
context.SaveChanges();
gvgrouptitle.DataBind();
break;
}
}
}
}
}