ASP.NET2.0下含有DropDownList的GridView编辑、…

2008-02-22 09:36:50来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

<asp:GridView ID="GridView1" runat="server" 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_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSorting="GridView1_Sorting" >
<Columns>
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# this.GridView1.PageIndex * this.GridView1.PageSize this.GridView1.Rows.Count 1%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="学历代码" 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>
<ItemTemplate>
<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>
<ItemTemplate>
<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="server" CausesValidation="True" CommandName="Update"
Text="更新"></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="编辑" OnClientClick="return confirm('确认要编辑吗?');"></asp:LinkButton>

<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" OnClientClick="return confirm('确认要删除吗?');"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Select"
Text="选择"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="Aquamarine" />
</asp:GridView>
/// <summary>
/// 绑定数据到GridView
/// </summary>
private void GridViewBind()
{
检索数据库
string strSql = "SELECT * FROM DB1";
得到数据集
this.GridView1.DataSource=conn.GetDs(strSql).Tables[0].DefaultView;
this.GridView1.DataBind();

}
/// <summary>
/// 编辑当前行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
//当前编辑行背景色高亮
this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
GridViewBind();
}
/// <summary>
/// 取消编辑状态
/// </summary>
/// <param name="sender"></param>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ASP.NET2.0下为GridView添加服务器端删除确认!

下一篇:asp.net关于文件在数据库的存入和读取