<asp:GridView ID="GridView1" runat="서버" AutoGenerateColumns="False" PageSize="10"
Width="542px" AllowPaging="True" AllowSorting="True"
DataKeyNames="DB31_1,DB31_2" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_Row DataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSorting="GridView1_Sorting" >
<열>
<asp:TemplateField HeaderText="序号">
<항목 템플릿>
<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="school历代码" SortExpression="DB1_1">
<EditItemTemplate>
<%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DB1_1") %>'></asp:TextBox>--%>
<asp:DropDownList ID ="ddlXL" runat="server" DataValueField='<%# Bind("DB1_1") %>'></asp:DropDownList>
</EditItemTemplate>
<항목 템플릿>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("xueliText") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="학술지명" SortExpression="DB1_2">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DB1_2") %>'></asp:TextBox>
</EditItemTemplate>
<항목 템플릿>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DB1_2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="작성" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="서버" CausesValidation="True" CommandName="업데이트"
Text="새로운 내용"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="서버" CausesValidation="False" CommandName="취소"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<항목 템플릿>
<asp:LinkButton ID="LinkButton1" runat="서버" CausesValidation="False" CommandName="편집"
Text="编辑" OnClientClick="반환 확인('确认要编辑吗?');"></asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="서버" CausesValidation="False" CommandName="삭제"
Text="删除" OnClientClick="반환 확인('确认要删除吗?');"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="서버" CausesValidation="False" CommandName="선택"
Text="选择"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</열>
<AlternatingRowStyle BackColor="아쿠아마린" />
</asp:그리드뷰>
/// <요약>
/// 확정된 GridView
/// </summary>
개인 무효 GridViewBind()
{
检索数据库
string strSql = "SELECT * FROM DB1";
得到数据集
this.GridView1.DataSource=conn.GetDs(strSql).Tables[0].DefaultView;
this.GridView1.DataBind();
}
/// <요약>
/// 编辑当前行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowEditing(개체 전송자, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
//当前编辑行背景color高亮
this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
GridViewBind();
}
/// <요약>
/// 取消编辑状态
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCancelingEdit(개체 전송자, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridViewBind();
}
/// <요약>
/// 删除记录过程
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDeleting(개체 전송자, GridViewDeleteEventArgs e)
{
//得到单位编号
string rowToDelete = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
//转换为整数
//int ID=Convert.ToInt32(rowToDelete);
//从数据库中删除
string str = "DB1에서 삭제 여기서 DB1_1=" + "'" + rowToDelete + "'" + "";
노력하다
{
conn.RunSql(str);
//중요한 새로운 결정
GridViewBind();
}
잡기 (예외예외)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
응답.끝();
}
}
/// <요약>
/// 更新记录过程
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowUpdating(개체 전송자, GridViewUpdateEventArgs e)
{
문자열 ID = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
문자열 DB1_1 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;
//string DB1_2 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
문자열 DB1_2 = (((DropDownList))GridView1.Rows[e.RowIndex].FindControl("ddlXL")).SelectedItem.Text;
//判断表单项是否공공并给单提示信息
if (DB1_1 == "" || DB1_2 == "")
{
conn.Alert("请输入完整信息!", 페이지);
반품;
}
노력하다
{
conn.BuilderEdit("select * from DB1 where DB1_1 ='" + ID + "'");
conn.dr["DB1_1"] = DB1_1;
conn.dr["DB1_2"] = DB1_2;
conn.BuilderEditClose();
}
잡기(OracleException 오류)
{
if (err.Code.ToString() == "1")
conn.Alert("错误: 已存 는 具有同主键的记录", Page);
또 다른
conn.Alert("错误:未能添加记录", Page);
}
Response.Write("<script 언어='javascript'>alert('数据已被保存!');</script>");
//返回浏览状态
GridView1.EditIndex = -1;
GridViewBind();
}
/// <요약>
/// 분할 작업
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_PageIndexChanging(개체 전송자, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridViewBind();
}
/// <요약>
/// 加入鼠标效果及为DropDownList绑定值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(개체 전송자, GridViewRowEventArgs e)
{
//为DropDownList를 고정합니다.
if (((DropDownList)e.Row.FindControl("ddlXL")) != null)
{
DropDownList ddlXL = (DropDownList)e.Row.FindControl("ddlXL");
ddlXL.Items.Clear();
ddlXL.Items.Add(new ListItem("博士", "1"));
ddlXL.Items.Add(new ListItem("硕士", "2"));
ddlXL.Items.Add(new ListItem("학술", "3"));
}
//加入鼠标滑过的高亮效果
if (e.Row.RowType == DataControlRowType.DataRow)//결정적인 이동 이전에 datarow를 실행하는 방식
{
//当鼠标放上去的时候 先保存当前行的背景颜color 并给附一颜color
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.BackgroundColor;this.style.BackgroundColor='yellow',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜color还원래 以前的颜color
e.Row.Attributes.Add("onmouseout", "this.style.BackgroundColor=currentcolor,this.style.fontWeight='';");
}
//单击行改变行背景颜color
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "this.style.BackgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
}
}