62,046
社区成员
发帖
与我相关
我的任务
分享
using System.Collections.Generic;
using System.Linq;
static public class BLL
{
private static List<TestType> ret;
static public IEnumerable<TestType> GetDatas(string cond1, string cond2)
{
if (ret == null)
{
ret = new List<TestType>();
for (int i = 0; i < 10; i++)
{
TestType x = new TestType
{
申请人名 = "王海波" + i.ToString(),
审核人名 = "",
审核意见 = ""
};
ret.Add(x);
}
}
var result = ret.Where(c => true);
if (cond1 != string.Empty)
result = result.Where(c => c.审核意见.Contains(cond1));
if (cond2 != string.Empty)
result = result.Where(c => c.审核人名 == cond2);
return result;
}
static public void UpdateRet(string name, string a, string b)
{
TestType line = ret.Where(x => x.申请人名 == name).FirstOrDefault();
if (line != null)
{
line.审核意见 = a;
line.审核人名 = b;
}
}
}
public class TestType
{
public string 申请人名 { get; set; }
public string 审核意见 { get; set; }
public string 审核人名 { get; set; }
}
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
this.GridView1.DataBind();
}
protected void GridView1_DataBinding(object sender, EventArgs e)
{
this.GridView1.DataSource = BLL.GetDatas(this.TextBox1.Text.Trim(), this.TextBox2.Text.Trim());
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
this.GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
this.GridView1.DataBind();
}
protected void 更新这一行(object sender, EventArgs e)
{
var bt = sender as LinkButton;
var a = (bt.FindControl("Label1") as Label).Text;
var b = (bt.FindControl("TextBox1") as TextBox).Text;
var c = (bt.FindControl("TextBox2") as TextBox).Text;
BLL.UpdateRet(a, b, c);
this.GridView1.EditIndex = -1;
this.GridView1.DataBind();
}
private string[] _审核意见 = null;
public string[] 审核意见
{
get
{
if (_审核意见 == null)
_审核意见 = new string[] { "", "同意", "不同意", "发回重审" };
return _审核意见;
}
}
protected void 选择审核意见(object sender, EventArgs e)
{
var list = sender as DropDownList;
var tb = list.FindControl("TextBox1") as TextBox;
tb.Text = list.SelectedValue;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
审核意见:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
审核人:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="重新查询" OnClick="Button1_Click" />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnDataBinding="GridView1_DataBinding"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:TemplateField HeaderText="申请人姓名" SortExpression="申请人名">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("申请人名") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("申请人名") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="审核意见" SortExpression="审核意见">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("审核意见") %>'></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# this.审核意见 %>"
AutoPostBack="true" OnSelectedIndexChanged="选择审核意见">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("审核意见") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="审核人名" SortExpression="审核人名">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("审核人名") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("审核人名") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" Text="更新"
OnClick="更新这一行"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
Text="编辑"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="Button2" runat="server" Text="什么也不做,专用来测试随机回发时页面状态是否正常" />
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e) {
if(!IsPostBack) {
BindGrid();
}
}
private void BindGrid() {
gridview1.DataSource = GetData();
gridview1.DataBind();
}
protected void Page_Load(object sender, EventArgs e) {
//if(!IsPostBack) {
BindGrid();
//}
}
private void BindGrid() {
gridview1.DataSource = GetData();
gridview1.DataBind();
}