【发布时间】:2014-01-03 16:44:48
【问题描述】:
我有一个网格视图:
折扣.aspx
<asp:GridView ID="GridView2" runat="server" BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
我通过 Discount.aspx.cs 的数据集填充它
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class Discount : System.Web.UI.Page
{
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
DBservices db2 = new DBservices();
SqlConnection con = db2.connect("storeConnectionString");
string SelectSTR = "SELECT * FROM Items";
SqlDataAdapter da = new SqlDataAdapter(SelectSTR, con);
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
int price;
for (int i = 0; i < GridView2.Rows.Count; i++)
{
if (Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[4]) > Convert.ToInt32(minamount.Text))
{
price = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[2]);
price= price*((100- Convert.ToInt32(discountrate.Text))/100);
ds.Tables[0].Rows[i].ItemArray[4] = price;
GridView2.DataBind();
}
}
}
}
如您所见,我试图更新数据集中的价格列,而不是更新 gridview,但问题是 gridview 没有任何变化......
谢谢你,祝你有美好的一天
【问题讨论】:
-
试试我更新的答案代码。
标签: c# asp.net gridview dataset