<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="DepartmentView.aspx.cs" Inherits="DepartmentView" Debug="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="c_MainLeft">
<ul style="text-align:left;">
<li style="list-style-type: none;height:120px;">
<img src="images/045.png" /></li><li style="list-style-type: none;height:40px;"></li>
<li style="list-style-type: none;height:40px;">共有 <asp:Label ID="lbl_Count" runat="server"
Style="color: red"></asp:Label> 个部门</li><li style="list-style-type: none;height:40px;"></li>
</ul>
</div>
<div class="c_MainRight">
<asp:Panel ID="pDepartmentMenu3" runat="server" CssClass="c_Menu3">
<asp:LinkButton ID="lbDepartmentAdd" runat="server" OnClick="lbDepartmentAdd_Click" CssClass="c_Menu3Button">新增</asp:LinkButton>
<asp:LinkButton ID="lbDepartmentEdit" runat="server" OnClick="lbDepartmentEdit_Click" CssClass="c_Menu3Button">修改</asp:LinkButton></asp:Panel>
<asp:GridView ID="GV_Department" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" Style="width: 100%" OnRowCancelingEdit="GV_Department_RowCancelingEdit" OnRowDeleting="GV_Department_RowDeleting" OnSelectedIndexChanging="GV_Department_SelectedIndexChanging">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="部门代码">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="部门名称">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="create_name" HeaderText="创建用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_name" HeaderText="更新用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="create_date" HeaderText="创建日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_date" HeaderText="更新日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:TemplateField HeaderText="有效标志">
<ItemTemplate>
<asp:DropDownList ID="SignID" Visible="false" width = "100%" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="选择" ShowSelectButton="True">
<HeaderStyle Width="8%" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="8%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("确认要删除吗?")' Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</asp:Content>
CS 文件 内容如下using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class DepartmentView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//DropDownList ddl;
if (!Page.IsPostBack)
{
//ddl.Items.Add("");
Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
//GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataSource = ds_Department.Tables["hr.dbo.v_hr_bm"];
GV_Department.DataBind();
//lbl_Count.Text = ds_Department.Tables["T_Department"].Rows.Count.ToString();
lbl_Count.Text = ds_Department.Tables["hr.dbo.v_hr_bm"].Rows.Count.ToString();
/*
SignDropDownList sign = new SignDropDownList();
DataSet ds_Sign = sign.GetDataSet("");
for (int i = 0; i <= ds_Sign.Tables["hr.dbo.hr_bz"].Rows.Count - 1; i++)
{
//ddl= ds_Sign.Tables["hr.dbo.hr_bz"].Rows[i].FindControl("id") as DropDownList;
//ddl= ds_Sign.Tables["hr.dbo.hr_bz"].Rows[i].FindControl("id") as DropDownList;
//ddl.Items.Add(ds_Sign.Tables["hr.dbo.hr_bz"].ToString());
}
//DropDownList dp=(DropDownList)gridview1.Rows[0].FinControl("ddl1");
//ddl.DataSource = ds_Sign;
//ddl.DataValueField = "id";
//ddl.DataTextField = "name";
//ddl.DataBind();
*/
//数据绑定
DataSet ds_Sign = new DataSet();
Sign sign = new Sign();
ds_Sign = sign.GetDataSet("");
SignID.DataSource = ds_Sign.Tables["hr.dbo.hr_bz"];
SignID.DataTextField = "name";
SignID.DataValueField = "id";
SignID.DataBind();
}
if (Request.Cookies["Rank_Code"] != null)
{
publicFunction pFunction = new publicFunction();
String strRankCode = Request.Cookies["Rank_Code"].Value;
String strFunctionCode = "Department";
String strReturn = pFunction.GetPurview(strRankCode, strFunctionCode);
if (strReturn.Contains("fail"))
Response.Redirect("PurviewError.aspx");
}
}
protected void GV_Department_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
int Int_SelectIndex = e.NewSelectedIndex; Response.Cookies["RowIndex"].Value = Int_SelectIndex.ToString(); Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
int Int_RowIndex = -1;
GV_Department.EditIndex = Int_RowIndex; Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int Int_RowIndex = e.RowIndex; Department department = new Department(); //删除部门
department.RowIndex = Int_RowIndex;
String strReturn = department.DepartmentDelete();
if (strReturn.Contains("ok"))
{
//获取新的部门信息列表
DataSet ds_Department = new DataSet();
ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
else if (strReturn.Contains("fail"))
{
Response.Write(strReturn.Replace("fail", ""));
}
}
protected void lbDepartmentAdd_Click(object sender, EventArgs e)
{
Response.Redirect("DepartmentEdit.aspx?Command=INSERT");
}
protected void lbDepartmentEdit_Click(object sender, EventArgs e)
{
//GridView GV_Department = (GridView)this.Parent.Controls[3].Controls[1];
Response.Redirect("DepartmentEdit.aspx?Command=UPDATE&RowIndex=" + GV_Department.SelectedIndex.ToString());
}
}编译后 出错说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误消息: CS0103: 当前上下文中不存在名称“SignID”源错误: 行 45: Sign sign = new Sign();
行 46: ds_Sign = sign.GetDataSet("");
行 47: SignID.DataSource = ds_Sign.Tables["hr.dbo.hr_bz"];
行 48: SignID.DataTextField = "name";
行 49: SignID.DataValueField = "id";
可我明明 已经在 aspx中定义了 见红色部分 请大虾 指点 谢谢
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="c_MainLeft">
<ul style="text-align:left;">
<li style="list-style-type: none;height:120px;">
<img src="images/045.png" /></li><li style="list-style-type: none;height:40px;"></li>
<li style="list-style-type: none;height:40px;">共有 <asp:Label ID="lbl_Count" runat="server"
Style="color: red"></asp:Label> 个部门</li><li style="list-style-type: none;height:40px;"></li>
</ul>
</div>
<div class="c_MainRight">
<asp:Panel ID="pDepartmentMenu3" runat="server" CssClass="c_Menu3">
<asp:LinkButton ID="lbDepartmentAdd" runat="server" OnClick="lbDepartmentAdd_Click" CssClass="c_Menu3Button">新增</asp:LinkButton>
<asp:LinkButton ID="lbDepartmentEdit" runat="server" OnClick="lbDepartmentEdit_Click" CssClass="c_Menu3Button">修改</asp:LinkButton></asp:Panel>
<asp:GridView ID="GV_Department" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" Style="width: 100%" OnRowCancelingEdit="GV_Department_RowCancelingEdit" OnRowDeleting="GV_Department_RowDeleting" OnSelectedIndexChanging="GV_Department_SelectedIndexChanging">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="部门代码">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="部门名称">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="create_name" HeaderText="创建用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_name" HeaderText="更新用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="create_date" HeaderText="创建日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_date" HeaderText="更新日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:TemplateField HeaderText="有效标志">
<ItemTemplate>
<asp:DropDownList ID="SignID" Visible="false" width = "100%" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="选择" ShowSelectButton="True">
<HeaderStyle Width="8%" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="8%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("确认要删除吗?")' Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</asp:Content>
CS 文件 内容如下using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class DepartmentView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//DropDownList ddl;
if (!Page.IsPostBack)
{
//ddl.Items.Add("");
Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
//GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataSource = ds_Department.Tables["hr.dbo.v_hr_bm"];
GV_Department.DataBind();
//lbl_Count.Text = ds_Department.Tables["T_Department"].Rows.Count.ToString();
lbl_Count.Text = ds_Department.Tables["hr.dbo.v_hr_bm"].Rows.Count.ToString();
/*
SignDropDownList sign = new SignDropDownList();
DataSet ds_Sign = sign.GetDataSet("");
for (int i = 0; i <= ds_Sign.Tables["hr.dbo.hr_bz"].Rows.Count - 1; i++)
{
//ddl= ds_Sign.Tables["hr.dbo.hr_bz"].Rows[i].FindControl("id") as DropDownList;
//ddl= ds_Sign.Tables["hr.dbo.hr_bz"].Rows[i].FindControl("id") as DropDownList;
//ddl.Items.Add(ds_Sign.Tables["hr.dbo.hr_bz"].ToString());
}
//DropDownList dp=(DropDownList)gridview1.Rows[0].FinControl("ddl1");
//ddl.DataSource = ds_Sign;
//ddl.DataValueField = "id";
//ddl.DataTextField = "name";
//ddl.DataBind();
*/
//数据绑定
DataSet ds_Sign = new DataSet();
Sign sign = new Sign();
ds_Sign = sign.GetDataSet("");
SignID.DataSource = ds_Sign.Tables["hr.dbo.hr_bz"];
SignID.DataTextField = "name";
SignID.DataValueField = "id";
SignID.DataBind();
}
if (Request.Cookies["Rank_Code"] != null)
{
publicFunction pFunction = new publicFunction();
String strRankCode = Request.Cookies["Rank_Code"].Value;
String strFunctionCode = "Department";
String strReturn = pFunction.GetPurview(strRankCode, strFunctionCode);
if (strReturn.Contains("fail"))
Response.Redirect("PurviewError.aspx");
}
}
protected void GV_Department_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
int Int_SelectIndex = e.NewSelectedIndex; Response.Cookies["RowIndex"].Value = Int_SelectIndex.ToString(); Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
int Int_RowIndex = -1;
GV_Department.EditIndex = Int_RowIndex; Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int Int_RowIndex = e.RowIndex; Department department = new Department(); //删除部门
department.RowIndex = Int_RowIndex;
String strReturn = department.DepartmentDelete();
if (strReturn.Contains("ok"))
{
//获取新的部门信息列表
DataSet ds_Department = new DataSet();
ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
else if (strReturn.Contains("fail"))
{
Response.Write(strReturn.Replace("fail", ""));
}
}
protected void lbDepartmentAdd_Click(object sender, EventArgs e)
{
Response.Redirect("DepartmentEdit.aspx?Command=INSERT");
}
protected void lbDepartmentEdit_Click(object sender, EventArgs e)
{
//GridView GV_Department = (GridView)this.Parent.Controls[3].Controls[1];
Response.Redirect("DepartmentEdit.aspx?Command=UPDATE&RowIndex=" + GV_Department.SelectedIndex.ToString());
}
}编译后 出错说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误消息: CS0103: 当前上下文中不存在名称“SignID”源错误: 行 45: Sign sign = new Sign();
行 46: ds_Sign = sign.GetDataSet("");
行 47: SignID.DataSource = ds_Sign.Tables["hr.dbo.hr_bz"];
行 48: SignID.DataTextField = "name";
行 49: SignID.DataValueField = "id";
可我明明 已经在 aspx中定义了 见红色部分 请大虾 指点 谢谢
解决方案 »
- 如何将GridView中读取出来的数字计算并显示成百分数
- 求救!怎么对年,月,日,周,季,小时分别进行判断?
- DataList中的CheckBox,使用了Attribute.Add后,服务器端事件不执行,求解!
- asp.net中怎样弹出选择对话框
- 在SQL2005中插入中文字符出现?号
- petshop算不算一种开发模式
- 各位大侠小弟高分求一代码!分数不够可以再加!
- 谁看过wrox的asp.net 电子商务高级编程或者对电子商务中打折和购物券有经验的进来~~~
- 客户端如何获取ToolbarDropDownList的事件?
- aspnetmenu的问题
- 使用Microsoft.Office.Interop.Excel制作excel图表,会的进
- 关于采集器的几个问题
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;/// <summary>
/// XueLi 的摘要说明
/// </summary>
public class Sign
{
public Sign()
{
//
// TODO: 在此处添加构造函数逻辑
//
} private String Sign_ID;
private String Sign_name;
private int intRowIndex; #region 属性代码 public String Field_Sign_ID
{
get
{
return Sign_ID;
}
set
{
Sign_ID = value;
}
} public String Field_Sign_name
{
get
{
return Sign_name;
}
set
{
Sign_name = value;
}
} public int RowIndex
{
get
{
return intRowIndex;
}
set
{
intRowIndex = value;
}
}
#endregion //返回符合条件的数据集
public DataSet GetDataSet(String strQuery)
{
ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; //得到连接字符串
String strConn = connectionStrings["strConn"].ConnectionString; String strSQL = ""; //判断查询条件
if (strQuery == "")
strSQL = "Select * From hr.dbo.hr_bz";
else
strSQL = "Select * From hr.dbo.hr_bz Where " + strQuery;
//连接数据库
SqlConnection connMain = new SqlConnection(strConn);
connMain.Open(); DataSet ds_Sign = new DataSet();
SqlDataAdapter dr_Sign = new SqlDataAdapter(strSQL, connMain); dr_Sign.Fill(ds_Sign, "hr.dbo.hr_bz"); //生成T_XueLi数据表的主键
ds_Sign.Tables["hr.dbo.hr_bz"].PrimaryKey = new DataColumn[] { ds_Sign.Tables["hr.dbo.hr_bz"].Columns["id"] }; return ds_Sign;
}
//返回符合条件的DataReader
public SqlDataReader GetDataReader(String strQuery)
{
ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; //得到连接字符串
String strConn = connectionStrings["strConn"].ConnectionString; String strSQL = ""; //判断查询条件
if (strQuery == "")
strSQL = "Select * From hr.dbo.hr_bz";
else
strSQL = "Select * From hr.dbo.hr_bz Where " + strQuery;
//连接数据库
SqlConnection connMain = new SqlConnection(strConn);
connMain.Open(); SqlCommand cmd_Sign = new SqlCommand(strSQL, connMain);
SqlDataReader SDR_Sign = cmd_Sign.ExecuteReader(); return SDR_Sign;
}
//插入新行
public String XueLiInsert()
{
/*
ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; //得到连接字符串
String strConn = connectionStrings["strConn"].ConnectionString; String strSQL = "INSERT INTO T_XueLi (";
strSQL += "XueLi_Code,";
strSQL += "XueLi_Name";
strSQL += ") VALUES (";
strSQL += "'" + XueLi_Code + "',";
strSQL += "'" + XueLi_Name + "')";
//连接数据库
SqlConnection connMain = new SqlConnection(strConn);
connMain.Open(); SqlCommand cmdXueLi = new SqlCommand(strSQL, connMain);
int intReturn = cmdXueLi.ExecuteNonQuery(); */
return "ok";
}
//更新记录
public String XueLiUpdate()
{
/*
ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; //得到连接字符串
String strConn = connectionStrings["strConn"].ConnectionString; //连接数据库
SqlConnection connMain = new SqlConnection(strConn);
connMain.Open(); String strSQL = "Select * From T_XueLi"; DataSet ds_XueLi = new DataSet();
SqlDataAdapter dr_XueLi = new SqlDataAdapter();
SqlCommandBuilder CB_XueLi = new SqlCommandBuilder(dr_XueLi);
dr_XueLi.SelectCommand = new SqlCommand(strSQL, connMain);
dr_XueLi.UpdateCommand = CB_XueLi.GetUpdateCommand(true); dr_XueLi.Fill(ds_XueLi, "T_XueLi"); //填充T_XueLi信息表 //生成T_XueLi数据表的主键
ds_XueLi.Tables["T_XueLi"].PrimaryKey = new DataColumn[] { ds_XueLi.Tables["T_XueLi"].Columns["XueLi_ID"] }; DataRow DR_XueLi = ds_XueLi.Tables["T_XueLi"].Rows[intRowIndex]; DR_XueLi["XueLi_Code"] = XueLi_Code;
DR_XueLi["XueLi_Name"] = XueLi_Name; dr_XueLi.Update(ds_XueLi); //把更新的信息发送到数据库 ds_XueLi.AcceptChanges(); */
return "ok";
}
//删除行
public String XueLiDelete()
{
/*
ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings; //得到连接字符串
String strConn = connectionStrings["strConn"].ConnectionString; //连接数据库
SqlConnection connMain = new SqlConnection(strConn);
connMain.Open(); String strSQL = "Select * From T_XueLi"; DataSet ds_XueLi = new DataSet();
SqlDataAdapter dr_XueLi = new SqlDataAdapter();
SqlCommandBuilder CB_XueLi = new SqlCommandBuilder(dr_XueLi);
dr_XueLi.SelectCommand = new SqlCommand(strSQL, connMain);
dr_XueLi.DeleteCommand = CB_XueLi.GetDeleteCommand(true); dr_XueLi.Fill(ds_XueLi, "T_XueLi"); //填充T_XueLi信息表 //生成T_XueLi数据表的主键
ds_XueLi.Tables["T_XueLi"].PrimaryKey = new DataColumn[] { ds_XueLi.Tables["T_XueLi"].Columns["XueLi_ID"] }; ds_XueLi.Tables["T_XueLi"].Rows.RemoveAt(RowIndex); dr_XueLi.Update(ds_XueLi); ds_XueLi.AcceptChanges(); */
return "ok";
}
}
{
DropDownList ddl = (DropDownList) e.Row.Cells[ 0 ].FindControl("SignID");
ddl.DataSource = ds_Sign;
ddl.DataValueField = "id";
ddl.DataTextField = "name";
ddl.DataBind();
}
protected void GV_Department_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dp = e.Row.FinControl("ddl1") as DropDownList;
DataSet ds_Sign = new DataSet();
Sign sign = new Sign();
ds_Sign = sign.GetDataSet("");
SignID.DataSource = ds_Sign.Tables["hr.dbo.hr_bz"];
SignID.DataTextField = "name";
SignID.DataValueField = "id";
SignID.DataBind(); }
}
ForeColor="#333333" Style="width: 100%" OnRowCancelingEdit="GV_Department_RowCancelingEdit"
OnRowDeleting="GV_Department_RowDeleting"
OnSelectedIndexChanging="GV_Department_SelectedIndexChanging"
onrowdatabound="GV_Department_RowDataBound">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="部门代码">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="部门名称">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="create_name" HeaderText="创建用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_name" HeaderText="更新用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="create_date" HeaderText="创建日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_date" HeaderText="更新日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:TemplateField HeaderText="有效标志">
<ItemTemplate>
<asp:DropDownList ID="SignID" Visible="false" Width="100%" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="选择" ShowSelectButton="True">
<HeaderStyle Width="8%" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="8%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("确认要删除吗?")' Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
protected void GV_Department_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ DropDownList ddl = e.Row.FindControl("SignID") as DropDownList;
if (ddl != null)
{
DDLBind(ddl);
}
}
} public void DDLBind(DropDownList ddl)
{
DataSet ds_Sign = sign.GetDataSet("");
ddl.DataSource = ds_Sign;
ddl.DataValueField = "id";
ddl.DataTextField = "name";
ddl.DataBind(); }
这个控件只会在程序运行的时候生成
而在程序编译的时候是没有的既然是动态生成的控件,那就要动态获取上面已经有人给出提示
你可以在绑定事件中获取到此控件,通过FindContol方法
e.Row.FinControl("SignID")
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="c_MainLeft">
<ul style="text-align:left;">
<li style="list-style-type: none;height:120px;">
<img src="images/045.png" /></li><li style="list-style-type: none;height:40px;"></li>
<li style="list-style-type: none;height:40px;">共有 <asp:Label ID="lbl_Count" runat="server"
Style="color: red"></asp:Label> 个部门</li><li style="list-style-type: none;height:40px;"></li>
</ul>
</div>
<div class="c_MainRight">
<asp:Panel ID="pDepartmentMenu3" runat="server" CssClass="c_Menu3">
<asp:LinkButton ID="lbDepartmentAdd" runat="server" OnClick="lbDepartmentAdd_Click" CssClass="c_Menu3Button">新增</asp:LinkButton>
<asp:LinkButton ID="lbDepartmentEdit" runat="server" OnClick="lbDepartmentEdit_Click" CssClass="c_Menu3Button">修改</asp:LinkButton></asp:Panel>
<asp:GridView ID="GV_Department" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" Style="width: 100%" OnRowCancelingEdit="GV_Department_RowCancelingEdit" OnRowDeleting="GV_Department_RowDeleting" OnSelectedIndexChanging="GV_Department_SelectedIndexChanging"
OnRowDataBound = "GV_Department_RowDataBound"> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="部门代码">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="部门名称">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="15%" />
</asp:BoundField>
<asp:BoundField DataField="create_name" HeaderText="创建用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_name" HeaderText="更新用户">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="create_date" HeaderText="创建日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="update_date" HeaderText="更新日期">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="12%" />
</asp:BoundField>
<asp:TemplateField HeaderText="有效标志">
<ItemTemplate>
<asp:DropDownList ID="SignID" Visible="true" width = "100%" runat = "server" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="选择" ShowSelectButton="True">
<HeaderStyle Width="8%" />
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="8%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("确认要删除吗?")' Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</asp:Content>
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class DepartmentView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["hr.dbo.v_hr_bm"];
GV_Department.DataBind();
lbl_Count.Text = ds_Department.Tables["hr.dbo.v_hr_bm"].Rows.Count.ToString();
}
if (Request.Cookies["Rank_Code"] != null)
{
publicFunction pFunction = new publicFunction();
String strRankCode = Request.Cookies["Rank_Code"].Value;
String strFunctionCode = "Department";
String strReturn = pFunction.GetPurview(strRankCode, strFunctionCode);
if (strReturn.Contains("fail"))
Response.Redirect("PurviewError.aspx");
}
}
protected void GV_Department_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
int Int_SelectIndex = e.NewSelectedIndex; Response.Cookies["RowIndex"].Value = Int_SelectIndex.ToString(); Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
int Int_RowIndex = -1;
GV_Department.EditIndex = Int_RowIndex; Department department = new Department();
DataSet ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
protected void GV_Department_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("SignID") as DropDownList;
if (ddl != null)
{
DDLBind(ddl);
}
}
}
public void DDLBind(DropDownList ddl)
{
DataSet ds_Sign = new DataSet();
Sign sign = new Sign();
ds_Sign = sign.GetDataSet("");
ddl.DataSource = ds_Sign;
ddl.DataValueField = "id";
ddl.DataTextField = "name";
ddl.DataBind();
}
protected void GV_Department_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int Int_RowIndex = e.RowIndex; Department department = new Department(); //删除部门
department.RowIndex = Int_RowIndex;
String strReturn = department.DepartmentDelete();
if (strReturn.Contains("ok"))
{
//获取新的部门信息列表
DataSet ds_Department = new DataSet();
ds_Department = department.GetDataSet("");
GV_Department.DataSource = ds_Department.Tables["T_Department"];
GV_Department.DataBind();
}
else if (strReturn.Contains("fail"))
{
Response.Write(strReturn.Replace("fail", ""));
}
}
protected void lbDepartmentAdd_Click(object sender, EventArgs e)
{
Response.Redirect("DepartmentEdit.aspx?Command=INSERT");
}
protected void lbDepartmentEdit_Click(object sender, EventArgs e)
{
//GridView GV_Department = (GridView)this.Parent.Controls[3].Controls[1];
Response.Redirect("DepartmentEdit.aspx?Command=UPDATE&RowIndex=" + GV_Department.SelectedIndex.ToString());
}
}红色部分 是 已修改的内容 谢谢 各位 大虾 指点
<asp:DropDownList ID="SignID" Visible="false" width = "100%" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>