a标签,DataGrid的数据绑定
1、function aa(id, url) {
//alert(id);
window.open(url + '&id=' + id, '', 'target=_blank,scrollbars=yes,top=100,left=200,width=600,height=400,scrolling=1');
}
function myOpenRule(id, myEvent, state) {
orientationwidth = 400;
orientationheight = 150;
newShowDiv('floatDiv', myEvent);
var temp = document.getElementById("fra审核");
temp.src = "AccountAudit.aspx?AccountState=" + state + "&AccountId=" + id;
return false;
}
function closeSheZhiField() {
newCloseDiv("floatDiv");
location.href = 'AccountManage.aspx';
}
2、DataGrid前台
<asp:DataGrid ID="dgInfo1" runat="server" Width="100%" AllowPaging="True" CellSpacing="2"
CellPadding="0" DataKeyField="ID" BorderWidth="0" AutoGenerateColumns="False"
PageSize="10" OnItemCommand="dgInfo1_ItemCommand1" OnPageIndexChanged="dgInfo1_PageIndexChanged1"
OnItemDataBound="dgInfo1_ItemDataBound">
<ItemStyle HorizontalAlign="Center" CssClass="td1"></ItemStyle>
<HeaderStyle HorizontalAlign="Center" BackColor="SkyBlue" ForeColor="White" CssClass="td2">
</HeaderStyle>
<Columns>
<asp:BoundColumn DataField="姓名" HeaderText="姓名">
<ItemStyle Width="6%"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="单位" HeaderText="人事单位" ItemStyle-Wrap="true">
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="登陆次数" HeaderText="登录次数">
<ItemStyle Width="5%"></ItemStyle>
</asp:BoundColumn>
<%--<asp:HyperLinkColumn DataTextField="初任培训状态" HeaderText="初任培训"
NavigateUrl='javascript:aa(this);'></asp:HyperLinkColumn>--%>
<asp:TemplateColumn HeaderText="初任培训" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy初任培训状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="调研报告" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy调研报告状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="工作笔记" ItemStyle-Width="5%">
<ItemTemplate>
<asp:HyperLink ID="hy工作笔记状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="工作案例" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy工作案例状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="实事工作" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy实事工作状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="中期小结" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy中期小结状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="实习总结" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy实习总结状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="义工服务" ItemStyle-Width="6%">
<ItemTemplate>
<asp:HyperLink ID="hy义工服务状态" runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="状态" ItemStyle-Width="6%">
<ItemTemplate>
<asp:Label ID="lbl状态" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="操作" ItemStyle-Width="250px">
<%--<ItemStyle Width="150px"></ItemStyle>--%>
<ItemTemplate>
<asp:Button ID="btnexamtab" runat="server" Text="导出试用期考核表" Width="140px" CommandName="ToWord"
CommandArgument='<%#Eval("ID") %>' class="button" />
<%--<asp:Button ID="btnjiexamtab" runat="server" Text="试用期定级表" Width="100px" class="button" /><br />--%>
<asp:Button ID="btndetail" runat="server" Text="编辑人员" Width="70px" CommandName="ToEdit"
CommandArgument='<%#Eval("ID") %>' class="button" />
<asp:Button ID="btnDel" runat="server" Text="删除人员" Width="70px" CommandName="ToDel"
CommandArgument='<%#Eval("ID") %>' class="button" />
<%-- <asp:Button ID="Btn审核人员" Runat="server" Text="审核人员" Width="120px" CommandName="To审核" CommandArgument='<%#Eval("ID") %>' class="button" />--%>
<%--<asp:Button ID="Btn取消审核" Runat="server" Text="取消审核" Width="120px" CommandName="To取消" CommandArgument='<%#Eval("ID") %>' class="button" />--%>
<input type="button" name="Btn审核人员" id="Btn审核人员" value="通过考核" class="button" runat="server"
style="cursor: hand; width: 70px" />
<input type="button" name="Btn取消审核" id="Btn取消审核" value="不通过考核" class="button" runat="server"
style="cursor: hand; width: 70px" />
<%--<asp:ImageButton ID="btnModify" Runat="server" CommandName="ToEdit" AlternateText="点击进行编辑" ImageUrl="~/images/i_edit.gif"></asp:ImageButton>
<asp:ImageButton ID="btnDelete" Runat="server" CommandName="ToDelete" ToolTip="点击删除当前项" ImageUrl="~/images/i_delete.gif"></asp:ImageButton>--%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
<div id="floatDiv" style="width: 300px; height: 180px; display: none; background-color: #7fbae2"
class="floatDiv" onmousedown="newMoveDiv(event,'floatDiv');">
<div id="Div1" style="display: inline; width: 300px; position: absolute;" align="center">
<strong id="fontTitle"></strong>
</div>
<span onclick="closeSheZhiField()" style="float: right; display: inline; cursor: hand">
×</span>
<iframe id="fra审核" src="" runat="server" width="300px" height="180px" style="border: 0"
scrolling="no"></iframe>
</div>
3、
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
#region Drp数据获取
DataTable dt = Comm.GetCodeByDH("03");
//DrpSex.DataSource = dt;
//DrpSex.DataTextField = "Chinese";
//DrpSex.DataValueField = "Code";
//DrpSex.DataBind();
//DrpSex.Items.Insert(0, new ListItem("请选择", string.Empty));
dt = Comm.获取数据("批次表", "1", "1", "创建时间 desc");
Drp批次.DataSource = dt;
Drp批次.DataTextField = "批次名称";
Drp批次.DataValueField = "ID";
Drp批次.DataBind();
Drp批次.Items.Insert(0, new ListItem("请选择", string.Empty));
#endregion
BinddgInfo1();
}
}
private void BinddgInfo1()
{
string 开题报告结束时间 = System.Configuration.ConfigurationManager.AppSettings["开题报告结束时间"];
string 服务小时数 = System.Configuration.ConfigurationManager.AppSettings["服务小时数"];
//this.dgInfo1.DataKeyField = "ID";
this.dgInfo1.DataSource = AccountRule.六个一管理显示(Manage, txtName.Text.Trim(), DrpSex.SelectedValue, Drp批次.SelectedValue, 开题报告结束时间, txt实习单位.Text.Trim(), 服务小时数);
this.dgInfo1.DataBind();
}
protected void dgInfo1_PageIndexChanged1(object source, DataGridPageChangedEventArgs e)
{
dgInfo1.CurrentPageIndex = e.NewPageIndex;
txtName.Text = string.Empty;
txt实习单位.Text = string.Empty;
Drp批次.SelectedValue = string.Empty;
DrpSex.SelectedValue = string.Empty;
this.BinddgInfo1();
}
protected void dgInfo1_ItemCommand1(object source, DataGridCommandEventArgs e)
{
if (e.CommandName.ToLower() == "toedit") //编辑人员
{
string keyId = e.CommandArgument.ToString();
string url = Request.ApplicationPath + @"Manager/AddAccount.aspx?AccountId=" + keyId;
Response.Write("<script>window.open('" + url + "' ,'','target=_blank,scrollbars=yes,top=100,left=200,width=600,height=400,scrolling=1');</script>");
}
//else if (e.CommandName == "To审核")
//{
// string keyId = e.CommandArgument.ToString();
// string url = Request.ApplicationPath + @"Manager/AccountAudit.aspx?AccountId=" + keyId;
// Response.Write("<script>window.showModalDialog('" + url + "' ,'','scrollbars=no;dialogWidth=400px;dialogHeight=280px');document.getElementById('btnSearch').click();</script>");
//}
else if (e.CommandName == "To取消") //取消审核
{
string keyId = e.CommandArgument.ToString();
Comm.更新数据(keyId, "试用期考核表", "审核意见='',状态=1");
BinddgInfo1();
}
else if (e.CommandName.ToLower() == "todel") //删除人员
{
string keyId = dgInfo1.DataKeys[e.Item.ItemIndex].ToString();
//if(!SurveyReportRule.Instance.DelSurveyReport(keyId) )
//{
// Page.RegisterStartupScript("msg","<script>alert('删除失败!')</script>");
// return;
//}
//else
//{
// Page.RegisterStartupScript("msg","<script>alert('删除成功!')</script>");
//}
//在分页状态下删除DATAGRID中的记录需要转换CurrentPageIndex值
//if (dgInfo1.Items.Count == 1 && dgInfo1.CurrentPageIndex > 0)
//{
// dgInfo1.CurrentPageIndex--;
//}
////重新绑定数据
//this.BinddgInfo1();
}
else if (e.CommandName.ToLower() == "toword") //导出word
{
//导出word
string ID = e.CommandArgument.ToString();
object missing = System.Reflection.Missing.Value;
string FileName = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath);//
//string aa = ;
string TemplateFile = FileName + @"Template\新录用公务员试用期满考核表.doc";
FileName += @"FckUploadfile\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
File.Copy(TemplateFile, FileName);
FileInfo fi = new FileInfo(FileName);
//判断文件属性是否只读?是则修改为一般属性再保存
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
fi.Attributes = FileAttributes.Normal;
}
Microsoft.Office.Interop.Word.Application App = new Microsoft.Office.Interop.Word.Application();
try
{
object Obj_FileName = FileName;
object Visible = false;
object ReadOnly = false;
Microsoft.Office.Interop.Word.Document Doc = App.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
Doc.Activate();
// Get the data and fill the data( PersonName ,PersonResume) to the appoint BookMark
DataRow row = AccountRule.导出试用期考核表信息获取(ID).Rows[0];
object BookMarkName = "姓名";
object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["姓名"].ToString());
BookMarkName = "性别";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["姓名"].ToString());
BookMarkName = "出生年月";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["出生年月"].ToString());
BookMarkName = "政治面貌";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["政治面貌"].ToString());
BookMarkName = "单位";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["单位"].ToString());
BookMarkName = "从事工作";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["从事工作"].ToString());
BookMarkName = "学历学位";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["学历"].ToString() + "\r\n" + row["学位"].ToString());
Doc.ActiveWindow.Selection.MoveDown(Microsoft.Office.Interop.Word.WdUnits.wdLine, 6);
BookMarkName = "试用期起止时间";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(row["试用期起止时间"].ToString());
BookMarkName = "个人总结";
Doc.ActiveWindow.Selection.GoTo(ref what, ref missing, ref missing, ref BookMarkName);
Doc.ActiveWindow.Selection.TypeText(Convert.IsDBNull(row["个人总结"]) ? string.Empty : row["个人总结"].ToString());
File.SetAttributes(FileName, FileAttributes.Normal);
Doc.Save();
// Save the File and change the File as stream
object IsSave = true;
Doc.Close(ref IsSave, ref missing, ref missing);
Get(FileName);
}
finally
{
App.Quit(ref missing, ref missing, ref missing);
}
//string url = Request.ApplicationPath + @"/qgy/dybg_File.aspx?KeyId=" + keyId;
//Response.Write("<script>window.open('" + url + "','','target=_blank,scrollbars=yes,top=100,left=200,width=600,height=300,scrolling=1');</script>");
}
}
public void Get(string fileName)
{
string paths = Request.MapPath("../FckUploadfile");
string file = Path.Combine(paths, fileName);
FileInfo fi = new FileInfo(file);
if (fi.Exists == true)
{
// const long ChunkSize = 1024;
// byte[] buffer = new byte[ChunkSize];
//Response.Clear();
FileStream istream = File.OpenRead(file);
try
{
byte[] buffer = new byte[istream.Length];
istream.Read(buffer, 0, buffer.Length);
istream.Seek(0, SeekOrigin.Begin);
Response.BinaryWrite(buffer);
//long Data = istream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(file.Substring(file.LastIndexOf("\\") + 1)));//
}
finally
{
}
}
}
protected void dgInfo1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRow row = ((DataRowView)e.Item.DataItem).Row;
HyperLink hy初任培训状态 = e.Item.FindControl("hy初任培训状态") as HyperLink;
//hy初任培训状态.Text = row["初任培训状态"].ToString();
HyperLink hy调研报告状态 = e.Item.FindControl("hy调研报告状态") as HyperLink;
//hy调研报告状态.Text = row["调研报告状态"].ToString();
HyperLink hy工作笔记状态 = e.Item.FindControl("hy工作笔记状态") as HyperLink;
//hy工作笔记状态.Text = row["工作笔记状态"].ToString();
HyperLink hy工作案例状态 = e.Item.FindControl("hy工作案例状态") as HyperLink;
//hy工作案例状态.Text = row["工作案例状态"].ToString();
HyperLink hy实事工作状态 = e.Item.FindControl("hy实事工作状态") as HyperLink;
//hy实事工作状态.Text = row["实事工作状态"].ToString();
HyperLink hy中期小结状态 = e.Item.FindControl("hy中期小结状态") as HyperLink;
//hy中期小结状态.Text = row["中期小结状态"].ToString();
HyperLink hy实习总结状态 = e.Item.FindControl("hy实习总结状态") as HyperLink;
//hy实习总结状态.Text = row["实习总结状态"].ToString();
HyperLink hy义工服务状态 = e.Item.FindControl("hy义工服务状态") as HyperLink;
//hy义工服务状态.Text = row["义工服务状态"].ToString();
Label lbl状态 = e.Item.FindControl("lbl状态") as Label;
Button btnexamtab = e.Item.FindControl("btnexamtab") as Button;
Button btndetail = e.Item.FindControl("btndetail") as Button;
Button btnDel = e.Item.FindControl("btnDel") as Button;
HtmlControl Btn审核人员 = e.Item.FindControl("Btn审核人员") as HtmlControl;
HtmlControl Btn取消审核 = e.Item.FindControl("Btn取消审核") as HtmlControl;
if (row["状态"].ToString() != "2")
btnexamtab.Visible = false;
string s = "javascript:void(0);";
hy初任培训状态.NavigateUrl = row["初任培训状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy_ssgz.aspx?OtherType=8');";
hy调研报告状态.NavigateUrl = row["调研报告状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy.aspx?OtherType=2');";
hy工作笔记状态.NavigateUrl = Convert.ToInt32(row["工作笔记状态"]) == 0 ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy.aspx?OtherType=4');";
hy工作案例状态.NavigateUrl = row["工作案例状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy_ssgz.aspx?OtherType=1');";
hy实事工作状态.NavigateUrl = row["实事工作状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy_ssgz.aspx?OtherType=3');";
hy中期小结状态.NavigateUrl = row["中期小结状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy_ssgz.aspx?OtherType=5');";
hy实习总结状态.NavigateUrl = row["实习总结状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy_ssgz.aspx?OtherType=6');";
hy义工服务状态.NavigateUrl = row["义工服务状态"].ToString() == "未提交" ? s : "javascript:aa('" + row["ID"].ToString() + "','qgy.aspx?OtherType=7');";
hy初任培训状态.Text = row["初任培训状态"].ToString() == "未提交" ? "未完成" : "已完成";
hy工作案例状态.Text = row["工作案例状态"].ToString() == "未提交" ? "未完成" : "已完成";
hy实事工作状态.Text = row["实事工作状态"].ToString() == "未提交" ? "未完成" : "已完成";
hy中期小结状态.Text = row["中期小结状态"].ToString() == "未提交" ? "未完成" : "已完成";
hy实习总结状态.Text = row["实习总结状态"].ToString() == "未提交" ? "未完成" : "已完成";
if (Convert.ToBoolean(row["开题报告是否完成"]) && Convert.ToBoolean(row["调研报告是否完成"]))
{
hy调研报告状态.Text = "已完成";
}
else if (!Convert.ToBoolean(row["开题报告是否完成"]))
{
hy调研报告状态.Text = "未完成";
hy调研报告状态.ToolTip = "开题报告未完成";
}
else if (!Convert.ToBoolean(row["调研报告是否完成"]))
{
hy调研报告状态.Text = "未完成";
hy调研报告状态.ToolTip = "调研报告未完成";
}
else
{
hy调研报告状态.Text = "未完成";
hy调研报告状态.ToolTip = "开题报告未完成;调研报告未完成";
}
if (Convert.ToInt32(row["工作笔记总条数"]) <= Convert.ToInt32(row["工作笔记已完成条数"]))
{
hy工作笔记状态.Text = "已完成";
}
else
{
hy工作笔记状态.Text = "未完成";
}
hy工作笔记状态.ToolTip = "工作笔记总条数:" + row["工作笔记总条数"] + "条;需完成:" + row["工作笔记需完成条数"] + "条;已完成: " + row["工作笔记已完成条数"] + "条";
if (Convert.ToInt32(row["义工服务已完成小时数"]) >= Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["服务小时数"]))
{
hy义工服务状态.Text = "已完成";
}
else
{
hy义工服务状态.Text = "未完成";
}
hy义工服务状态.ToolTip = "义工服务总小时数:" + System.Configuration.ConfigurationManager.AppSettings["服务小时数"] + "小时;已完成: " + row["义工服务已完成小时数"].ToString() + "小时";
//是否审核权限
if (IsManage)
{
if (Convert.ToInt32(row["状态"]) == 1)
{
//Btn取消审核.Visible = false;
lbl状态.Text = "未通过";
lbl状态.ToolTip = row["审核意见"].ToString();
}
else
{
//btndetail.Visible = false;
//btnDel.Visible = false;
//Btn审核人员.Visible = false;
lbl状态.Text = "通过";
lbl状态.ToolTip = row["审核意见"].ToString();
}
}
else
{
Btn取消审核.Visible = false;
Btn审核人员.Visible = false;
}
Btn审核人员.Attributes.Add("onclick", "myOpenRule('" + row["id"].ToString() + "',event,2);document.getElementById('fontTitle').innerHTML= '通过考核'");
Btn取消审核.Attributes.Add("onclick", "myOpenRule('" + row["id"].ToString() + "',event,1);document.getElementById('fontTitle').innerHTML= '不通过考核'");
//Btn审核人员.Attributes.Add("OnClick", "window.showModalDialog('" + Request.ApplicationPath + @"Manager/AccountAudit.aspx?AccountId=" + row["id"].ToString() + "','','dialogWidth=400px;dialogHeight=280px;help:no;resizeable:yes;status:no;');");
}
}
}