RadioButtonList specialRadioButtonList = (RadioButtonList)gvwProduct.Rows[e.NewEditIndex].FindControl("RadioButtonList1");
DropDownList categoryIdDropDownList = (DropDownList)gvwProduct.Rows[e.NewEditIndex].FindControl("DropDownList1");
specialRadioButtonList.SelectedValue = specialLabel.Text;
categoryIdDropDownList.DataSource = CategoryOper.GetAll();
categoryIdDropDownList.DataTextField = "categoryName";
categoryIdDropDownList.DataValueField = "categoryId";
categoryIdDropDownList.DataBind();
categoryIdDropDownList.SelectedValue = categoryIdLabel.Text;
}
protected void gvwProduct_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消编辑模式
gvwProduct.EditIndex = -1;
//更新数据
Bind();
}
protected void gvwProduct_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据
//1,准备条件
Label productIdLabel = (Label)gvwProduct.Rows[e.RowIndex].FindControl("Label6");
TextBox productNameTextBox = (TextBox)gvwProduct.Rows[e.RowIndex].FindControl("TextBox2");
TextBox unitpriceTextBox = (TextBox)gvwProduct.Rows[e.RowIndex].FindControl("TextBox3");
RadioButtonList specialRadioButtonList = (RadioButtonList)gvwProduct.Rows[e.RowIndex].FindControl("RadioButtonList1");
DropDownList categoryIdDropDownList = (DropDownList)gvwProduct.Rows[e.RowIndex].FindControl("DropDownList1");
ProductInfo dal = new ProductInfo() {
ProductId=Convert.ToInt32(productIdLabel.Text),
ProductName=productNameTextBox.Text,
Unitprice=Convert.ToDecimal(unitpriceTextBox.Text),
Special=specialRadioButtonList.SelectedValue,
CategoryId=Convert.ToInt32(categoryIdDropDownList.SelectedValue)
};
//2,调用方法
ProductOper.Update(dal);
//取消编辑模式
gvwProduct.EditIndex = -1;
//更新数据
Bind();
}
protected void gvwProduct_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwProduct.PageIndex = e.NewPageIndex;
//更新数据
Bind();
}
}
/Create.aspx
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Create.aspx.cs" Inherits="Create" %>
<!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 runat="server">
<div>
<asp:HyperLink runat="server" Text="产品列表" NavigateUrl="~/Default.aspx"></asp:HyperLink>
<fieldset>
<legend>添加商品</legend>
<table>
<tr>
<td>产品名称</td>
<td>
<asp:TextBox runat="server"></asp:TextBox>
</td>
<td></td>
</tr>
<tr>
<td>单价</td>
<td>
<asp:TextBox runat="server"></asp:TextBox>
</td>
<td></td>
</tr>
<tr>
<td>是否特价</td>
<td>
<asp:RadioButtonList runat="server"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem>特价</asp:ListItem>
<asp:ListItem Selected="True">非特价</asp:ListItem>
</asp:RadioButtonList>
</td>
<td></td>
</tr>
<tr>
<td>类别</td>
<td>
<asp:DropDownList runat="server">
</asp:DropDownList>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button runat="server" Text="添加" />
</td>
<td></td>
</tr>
</table>
</fieldset>
</div>
</form>
</body>
</html>
/Create.aspx.cs
复制代码 代码如下:
using System;