前台代码:
<span>班级名:</span>
<telerik:RadComboBox ID="RCClas" runat="server"/>
<span>学生名:</span>
<telerik:RadTextBox ID="RTxtName" runat="server"/>
<telerik:RadButton ID="RBntSelect" runat="server" Text="查询" OnClick="RBntSelect_Click"/>
<br />
<telerik:RadGrid ID="RGStudent" runat="server" OnNeedDataSource="RGStudent_NeedDataSource" PageSize="2" AllowPaging="true" Skin="Office2010Blue">
前台代码:
<span>班级名:</span>
<telerik:RadComboBox ID="RCClas" runat="server"/>
<span>学生名:</span>
<telerik:RadTextBox ID="RTxtName" runat="server"/>
<telerik:RadButton ID="RBntSelect" runat="server" Text="查询" OnClick="RBntSelect_Click"/>
<br />
<telerik:RadGrid ID="RGStudent" runat="server" OnNeedDataSource="RGStudent_NeedDataSource" PageSize="2" AllowPaging="true" Skin="Office2010Blue">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn HeaderText="操作">
<ItemTemplate>
<telerik:RadButton runat="server" Text="删除" CommandArgument='<%#Eval("学生编号") %>' ID="RBDelete" OnClick="RBDelete_Click" OnClientClick="ConfirmDelete()"></telerik:RadButton>
<telerik:RadButton runat="server" Text="修改" CommandArgument='<%#Eval("学生编号") %>' ID="RBUpadte" OnClick="RBUpadte_Click"></telerik:RadButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<span>姓名:</span>
<telerik:RadTextBox ID="rName" runat="server"/><br />
<span>年龄:</span>
<telerik:RadTextBox ID="rage" runat="server"/><br />
<span>班级:</span>
<telerik:RadComboBox ID="rclass" runat="server"/><br />
<span>性别:</span>
<telerik:RadTextBox ID="rsex" runat="server"/><br />
<telerik:RadButton ID="rbtn" runat="server" Text="新增" OnClick="rbtn_Click"/>
后台代码:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.OpenAccess;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using UI;
using System.Linq;
public partial class Default : System.Web.UI.Page
{
#region 全局属性
EntitiesModel1 linq = new EntitiesModel1();
static int UID = 0;
#endregion
#region 页面加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var temp = linq.Clas;
RCClas.DataSource = temp;
RCClas.DataValueField = "Id";
RCClas.DataTextField = "name";
RCClas.DataBind();
RCClas.Items.Insert(0, new RadComboBoxItem("请选择", "0"));
rclass.DataSource = temp;
rclass.DataValueField = "Id";
rclass.DataTextField = "name";
rclass.DataBind();
rclass.Items.Insert(0, new RadComboBoxItem("请选择", "0"));
}
}
#endregion
#region 查询按钮点击事件
protected void RBntSelect_Click(object sender, EventArgs e)
{
initdata();
RGStudent.DataBind();
}
#endregion
#region 查询
private void initdata()
{
var temp = linq.Stus.Select(s => new
{
学生编号 = s.ID,
学生姓名 = s.NAME,
学生性别 = s.Sex,
学生年龄 = s.Age,
学生班级 = s.Cla.Name
});
if (RCClas.SelectedValue.ToString() != "0")
temp = temp.Where(s => s.学生班级 == RCClas.Text);
if (!string.IsNullOrEmpty(RTxtName.Text))
temp = temp.Where(s => s.学生姓名.Contains(RTxtName.Text));
RGStudent.DataSource = temp.ToList();
}
#endregion
#region radGird数据绑定
protected void RGStudent_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
initdata();
}
#endregion
protected void RBDelete_Click(object sender, EventArgs e)
{
RadButton btn = (RadButton)sender;
int ID = Convert.ToInt32(btn.CommandArgument);
DelStu(ID);
initdata();
RGStudent.DataBind();
}
private void updateStu(int id)
{
var temp = linq.Stus.Single(s => s.ID == id);
temp.CId = Convert.ToInt32(rclass.SelectedValue);
temp.Age = Convert.ToInt32(rage.Text);
temp.Sex = rsex.Text;
temp.NAME = rName.Text;
linq.SaveChanges();
}
#region 删除
private void DelStu(int ID)
{
var temp = linq.Stus.Single(s => s.ID == ID);
linq.Delete(temp);
linq.SaveChanges();
}
#endregion
#region 新增
private void insertStu(Stu temp) {
linq.Add(temp);
linq.SaveChanges();
}
#endregion
protected void RBUpadte_Click(object sender, EventArgs e)
{
RadButton btn = (RadButton)sender;
UID = Convert.ToInt32(btn.CommandArgument);
var temp = linq.Stus.SingleOrDefault(s => s.ID == UID);
rclass.SelectedValue = temp.CId.ToString();
rage.Text = temp.Age.ToString();
rsex.Text = temp.Sex;
rName.Text = temp.NAME;
rbtn.Text = "修改";
}
protected void rbtn_Click(object sender, EventArgs e)
{
if (this.rbtn.Text == "新增"){
Stu temp = new Stu() {
CId = Convert.ToInt32(rclass.SelectedValue),
Age = Convert.ToInt32( rage.Text),
Sex = rsex.Text,
NAME = rName.Text
};
insertStu(temp);
initdata();
RGStudent.DataBind();
}
else {
updateStu(UID);
initdata();
RGStudent.DataBind();
this.rbtn.Text = "新增";
}
}
}
<MasterTableView> <Columns> <telerik:GridTemplateColumn HeaderText="操作"> <ItemTemplate> <telerik:RadButton runat="server" Text="删除" CommandArgument='<%#Eval("学生编号") %>' ID="RBDelete" OnClick="RBDelete_Click" OnClientClick="ConfirmDelete()"></telerik:RadButton> <telerik:RadButton runat="server" Text="修改" CommandArgument='<%#Eval("学生编号") %>' ID="RBUpadte" OnClick="RBUpadte_Click"></telerik:RadButton> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> <span>姓名:</span> <telerik:RadTextBox ID="rName" runat="server"/><br /> <span>年龄:</span> <telerik:RadTextBox ID="rage" runat="server"/><br /> <span>班级:</span> <telerik:RadComboBox ID="rclass" runat="server"/><br /> <span>性别:</span> <telerik:RadTextBox ID="rsex" runat="server"/><br /> <telerik:RadButton ID="rbtn" runat="server" Text="新增" OnClick="rbtn_Click"/> 后台代码: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.OpenAccess; using System.Data; using System.Configuration; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Telerik.Web.UI; using UI; using System.Linq; public partial class Default : System.Web.UI.Page { #region 全局属性 EntitiesModel1 linq = new EntitiesModel1(); static int UID = 0; #endregion #region 页面加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var temp = linq.Clas; RCClas.DataSource = temp; RCClas.DataValueField = "Id"; RCClas.DataTextField = "name"; RCClas.DataBind(); RCClas.Items.Insert(0, new RadComboBoxItem("请选择", "0")); rclass.DataSource = temp; rclass.DataValueField = "Id"; rclass.DataTextField = "name"; rclass.DataBind(); rclass.Items.Insert(0, new RadComboBoxItem("请选择", "0")); } } #endregion #region 查询按钮点击事件 protected void RBntSelect_Click(object sender, EventArgs e) { initdata(); RGStudent.DataBind(); } #endregion #region 查询 private void initdata() { var temp = linq.Stus.Select(s => new { 学生编号 = s.ID, 学生姓名 = s.NAME, 学生性别 = s.Sex, 学生年龄 = s.Age, 学生班级 = s.Cla.Name }); if (RCClas.SelectedValue.ToString() != "0") temp = temp.Where(s => s.学生班级 == RCClas.Text); if (!string.IsNullOrEmpty(RTxtName.Text)) temp = temp.Where(s => s.学生姓名.Contains(RTxtName.Text)); RGStudent.DataSource = temp.ToList(); } #endregion #region radGird数据绑定 protected void RGStudent_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { initdata(); } #endregion protected void RBDelete_Click(object sender, EventArgs e) { RadButton btn = (RadButton)sender; int ID = Convert.ToInt32(btn.CommandArgument); DelStu(ID); initdata(); RGStudent.DataBind(); } private void updateStu(int id) { var temp = linq.Stus.Single(s => s.ID == id); temp.CId = Convert.ToInt32(rclass.SelectedValue); temp.Age = Convert.ToInt32(rage.Text); temp.Sex = rsex.Text; temp.NAME = rName.Text; linq.SaveChanges(); } #region 删除 private void DelStu(int ID) { var temp = linq.Stus.Single(s => s.ID == ID); linq.Delete(temp); linq.SaveChanges(); } #endregion #region 新增 private void insertStu(Stu temp) { linq.Add(temp); linq.SaveChanges(); } #endregion protected void RBUpadte_Click(object sender, EventArgs e) { RadButton btn = (RadButton)sender; UID = Convert.ToInt32(btn.CommandArgument); var temp = linq.Stus.SingleOrDefault(s => s.ID == UID); rclass.SelectedValue = temp.CId.ToString(); rage.Text = temp.Age.ToString(); rsex.Text = temp.Sex; rName.Text = temp.NAME; rbtn.Text = "修改"; } protected void rbtn_Click(object sender, EventArgs e) { if (this.rbtn.Text == "新增"){ Stu temp = new Stu() { CId = Convert.ToInt32(rclass.SelectedValue), Age = Convert.ToInt32( rage.Text), Sex = rsex.Text, NAME = rName.Text }; insertStu(temp); initdata(); RGStudent.DataBind(); } else { updateStu(UID); initdata(); RGStudent.DataBind(); this.rbtn.Text = "新增"; } } }
<span>班级名:</span>
<telerik:RadComboBox ID="RCClas" runat="server"/>
<span>学生名:</span>
<telerik:RadTextBox ID="RTxtName" runat="server"/>
<telerik:RadButton ID="RBntSelect" runat="server" Text="查询" OnClick="RBntSelect_Click"/>
<br />
<telerik:RadGrid ID="RGStudent" runat="server" OnNeedDataSource="RGStudent_NeedDataSource" PageSize="2" AllowPaging="true" Skin="Office2010Blue">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn HeaderText="操作">
<ItemTemplate>
<telerik:RadButton runat="server" Text="删除" CommandArgument='<%#Eval("学生编号") %>' ID="RBDelete" OnClick="RBDelete_Click" OnClientClick="ConfirmDelete()"></telerik:RadButton>
<telerik:RadButton runat="server" Text="修改" CommandArgument='<%#Eval("学生编号") %>' ID="RBUpadte" OnClick="RBUpadte_Click"></telerik:RadButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<span>姓名:</span>
<telerik:RadTextBox ID="rName" runat="server"/><br />
<span>年龄:</span>
<telerik:RadTextBox ID="rage" runat="server"/><br />
<span>班级:</span>
<telerik:RadComboBox ID="rclass" runat="server"/><br />
<span>性别:</span>
<telerik:RadTextBox ID="rsex" runat="server"/><br />
<telerik:RadButton ID="rbtn" runat="server" Text="新增" OnClick="rbtn_Click"/>
后台代码:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.OpenAccess;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using UI;
using System.Linq;
public partial class Default : System.Web.UI.Page
{
#region 全局属性
EntitiesModel1 linq = new EntitiesModel1();
static int UID = 0;
#endregion
#region 页面加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var temp = linq.Clas;
RCClas.DataSource = temp;
RCClas.DataValueField = "Id";
RCClas.DataTextField = "name";
RCClas.DataBind();
RCClas.Items.Insert(0, new RadComboBoxItem("请选择", "0"));
rclass.DataSource = temp;
rclass.DataValueField = "Id";
rclass.DataTextField = "name";
rclass.DataBind();
rclass.Items.Insert(0, new RadComboBoxItem("请选择", "0"));
}
}
#endregion
#region 查询按钮点击事件
protected void RBntSelect_Click(object sender, EventArgs e)
{
initdata();
RGStudent.DataBind();
}
#endregion
#region 查询
private void initdata()
{
var temp = linq.Stus.Select(s => new
{
学生编号 = s.ID,
学生姓名 = s.NAME,
学生性别 = s.Sex,
学生年龄 = s.Age,
学生班级 = s.Cla.Name
});
if (RCClas.SelectedValue.ToString() != "0")
temp = temp.Where(s => s.学生班级 == RCClas.Text);
if (!string.IsNullOrEmpty(RTxtName.Text))
temp = temp.Where(s => s.学生姓名.Contains(RTxtName.Text));
RGStudent.DataSource = temp.ToList();
}
#endregion
#region radGird数据绑定
protected void RGStudent_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
initdata();
}
#endregion
protected void RBDelete_Click(object sender, EventArgs e)
{
RadButton btn = (RadButton)sender;
int ID = Convert.ToInt32(btn.CommandArgument);
DelStu(ID);
initdata();
RGStudent.DataBind();
}
private void updateStu(int id)
{
var temp = linq.Stus.Single(s => s.ID == id);
temp.CId = Convert.ToInt32(rclass.SelectedValue);
temp.Age = Convert.ToInt32(rage.Text);
temp.Sex = rsex.Text;
temp.NAME = rName.Text;
linq.SaveChanges();
}
#region 删除
private void DelStu(int ID)
{
var temp = linq.Stus.Single(s => s.ID == ID);
linq.Delete(temp);
linq.SaveChanges();
}
#endregion
#region 新增
private void insertStu(Stu temp) {
linq.Add(temp);
linq.SaveChanges();
}
#endregion
protected void RBUpadte_Click(object sender, EventArgs e)
{
RadButton btn = (RadButton)sender;
UID = Convert.ToInt32(btn.CommandArgument);
var temp = linq.Stus.SingleOrDefault(s => s.ID == UID);
rclass.SelectedValue = temp.CId.ToString();
rage.Text = temp.Age.ToString();
rsex.Text = temp.Sex;
rName.Text = temp.NAME;
rbtn.Text = "修改";
}
protected void rbtn_Click(object sender, EventArgs e)
{
if (this.rbtn.Text == "新增"){
Stu temp = new Stu() {
CId = Convert.ToInt32(rclass.SelectedValue),
Age = Convert.ToInt32( rage.Text),
Sex = rsex.Text,
NAME = rName.Text
};
insertStu(temp);
initdata();
RGStudent.DataBind();
}
else {
updateStu(UID);
initdata();
RGStudent.DataBind();
this.rbtn.Text = "新增";
}
}
}
<MasterTableView> <Columns> <telerik:GridTemplateColumn HeaderText="操作"> <ItemTemplate> <telerik:RadButton runat="server" Text="删除" CommandArgument='<%#Eval("学生编号") %>' ID="RBDelete" OnClick="RBDelete_Click" OnClientClick="ConfirmDelete()"></telerik:RadButton> <telerik:RadButton runat="server" Text="修改" CommandArgument='<%#Eval("学生编号") %>' ID="RBUpadte" OnClick="RBUpadte_Click"></telerik:RadButton> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> <span>姓名:</span> <telerik:RadTextBox ID="rName" runat="server"/><br /> <span>年龄:</span> <telerik:RadTextBox ID="rage" runat="server"/><br /> <span>班级:</span> <telerik:RadComboBox ID="rclass" runat="server"/><br /> <span>性别:</span> <telerik:RadTextBox ID="rsex" runat="server"/><br /> <telerik:RadButton ID="rbtn" runat="server" Text="新增" OnClick="rbtn_Click"/> 后台代码: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.OpenAccess; using System.Data; using System.Configuration; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Telerik.Web.UI; using UI; using System.Linq; public partial class Default : System.Web.UI.Page { #region 全局属性 EntitiesModel1 linq = new EntitiesModel1(); static int UID = 0; #endregion #region 页面加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var temp = linq.Clas; RCClas.DataSource = temp; RCClas.DataValueField = "Id"; RCClas.DataTextField = "name"; RCClas.DataBind(); RCClas.Items.Insert(0, new RadComboBoxItem("请选择", "0")); rclass.DataSource = temp; rclass.DataValueField = "Id"; rclass.DataTextField = "name"; rclass.DataBind(); rclass.Items.Insert(0, new RadComboBoxItem("请选择", "0")); } } #endregion #region 查询按钮点击事件 protected void RBntSelect_Click(object sender, EventArgs e) { initdata(); RGStudent.DataBind(); } #endregion #region 查询 private void initdata() { var temp = linq.Stus.Select(s => new { 学生编号 = s.ID, 学生姓名 = s.NAME, 学生性别 = s.Sex, 学生年龄 = s.Age, 学生班级 = s.Cla.Name }); if (RCClas.SelectedValue.ToString() != "0") temp = temp.Where(s => s.学生班级 == RCClas.Text); if (!string.IsNullOrEmpty(RTxtName.Text)) temp = temp.Where(s => s.学生姓名.Contains(RTxtName.Text)); RGStudent.DataSource = temp.ToList(); } #endregion #region radGird数据绑定 protected void RGStudent_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { initdata(); } #endregion protected void RBDelete_Click(object sender, EventArgs e) { RadButton btn = (RadButton)sender; int ID = Convert.ToInt32(btn.CommandArgument); DelStu(ID); initdata(); RGStudent.DataBind(); } private void updateStu(int id) { var temp = linq.Stus.Single(s => s.ID == id); temp.CId = Convert.ToInt32(rclass.SelectedValue); temp.Age = Convert.ToInt32(rage.Text); temp.Sex = rsex.Text; temp.NAME = rName.Text; linq.SaveChanges(); } #region 删除 private void DelStu(int ID) { var temp = linq.Stus.Single(s => s.ID == ID); linq.Delete(temp); linq.SaveChanges(); } #endregion #region 新增 private void insertStu(Stu temp) { linq.Add(temp); linq.SaveChanges(); } #endregion protected void RBUpadte_Click(object sender, EventArgs e) { RadButton btn = (RadButton)sender; UID = Convert.ToInt32(btn.CommandArgument); var temp = linq.Stus.SingleOrDefault(s => s.ID == UID); rclass.SelectedValue = temp.CId.ToString(); rage.Text = temp.Age.ToString(); rsex.Text = temp.Sex; rName.Text = temp.NAME; rbtn.Text = "修改"; } protected void rbtn_Click(object sender, EventArgs e) { if (this.rbtn.Text == "新增"){ Stu temp = new Stu() { CId = Convert.ToInt32(rclass.SelectedValue), Age = Convert.ToInt32( rage.Text), Sex = rsex.Text, NAME = rName.Text }; insertStu(temp); initdata(); RGStudent.DataBind(); } else { updateStu(UID); initdata(); RGStudent.DataBind(); this.rbtn.Text = "新增"; } } }