Hashtable ht = new Hashtable();
ht.Add(1, 单价 + 货号 + 尺寸);GridView1.DataSource = ht. //我要gridview1 添加ht的 表数据 我该如何操作
用不用 dataset??
ht.Add(1, 单价 + 货号 + 尺寸);GridView1.DataSource = ht. //我要gridview1 添加ht的 表数据 我该如何操作
用不用 dataset??
protected void lnkbtnUpdate_Click(object sender, EventArgs e)
{
hashCar = (Hashtable)Session["ShopCart"]; //获取其购物车
foreach (GridViewRow gvRow in gvShopCart.Rows)
{
TextBox tb = (TextBox)gvRow.FindControl("txtNum");
int count = Int32.Parse(tb.Text); //获取商品数量
int GoodsID =Convert.ToInt32(gvRow.Cells[2].Text); //获取商品ID
hashCar[GoodsID] = count;
}
Session["ShopCart"] = hashCar;//更新购物车
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "click", "<script language='javascript'>window.location.href=window.location.href;</script>", false);
}
hsCodes.Add("key2", "value2");
hsCodes.Add("key3", "value3");
hsCodes.Add("key4", "value4"); DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("key", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("value", System.Type.GetType("System.String"))); //取得hsCodes中的数据放到DataTable中
IDictionaryEnumerator myEnumerator = hsCodes.GetEnumerator();
while (myEnumerator.MoveNext())
{
dt.Rows.Add(new string[] { Convert.ToString(myEnumerator.Key), Convert.ToString(myEnumerator.Value) });
}
this.dataGridView1.DataSource = dt;
估计你最后少了句
GridView1.DataBind();
{
MultiView1.ActiveViewIndex = 9;
string cs, gg, cc, qc, sj;
cs = GridView2.Rows[e.NewSelectedIndex].Cells[2].Text.ToString();
gg = GridView2.Rows[e.NewSelectedIndex].Cells[3].Text.ToString();
cc = GridView2.Rows[e.NewSelectedIndex].Cells[4].Text.ToString();
qc = GridView2.Rows[e.NewSelectedIndex].Cells[5].Text.ToString();
Hashtable ht = new Hashtable();
ht.Add(1, cs + gg + cc + qc);
SqlDataAdapter sda = new SqlDataAdapter(
这里面我不知道怎么写 应该是ht的数据吧);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = sda;
GridView1.DataBind();
}
Hashtable hashCar;//设置购物车内容的数据源
dtTable = new DataTable();
DataColumn column1 = new DataColumn("No"); //序号列
DataColumn column2 = new DataColumn("GoodsID"); //商品代号
DataColumn column3 = new DataColumn("GoodsName"); //商品名称
DataColumn column4 = new DataColumn("Num"); //数量
dtTable.Columns.Add(column1); //添加新列
dtTable.Columns.Add(column2);
dtTable.Columns.Add(column3);
dtTable.Columns.Add(column4);
DataRow row;
//对数据表中每一行进行遍历,给每一行的新列赋值
foreach (object key in hashCar.Keys)
{
row = dtTable.NewRow();
row["GoodsID"] = key.ToString();
row["Num"] = hashCar[key].ToString();
dtTable.Rows.Add(row);
}foreach (DataRow drRow in dtTable.Rows)
{
strSql = "select * from View_GT where GoodsID=" + Convert.ToInt32(drRow["GoodsID"].ToString());
DataSet ds = Base.GetDataSet(strSql, "tb");
DataRowView row1 = ds.Tables["tb"].DefaultView[0]; drRow["No"] = i; //序号
drRow["GoodsName"] = row1["GoodsName"].ToString(); //名称
}
gvShopCart.DataSource = dtTable.DefaultView; //绑定GridView控件
gvShopCart.DataKeyNames = new string[] { "GoodsID" };
gvShopCart.DataBind();
看来这个问题虽然简单 还是不太好解决啊!
这里已经用到哈希表数据//对数据表中每一行进行遍历,给每一行的新列赋值
foreach (object key in hashCar.Keys)
{
row = dtTable.NewRow();
row["GoodsID"] = key.ToString();
row["Num"] = hashCar[key].ToString();
dtTable.Rows.Add(row);
}