我可以使用数据集向Gridview列添加变量值 [英] Can I add a variable value to Gridview column using dataset

查看:60
本文介绍了我可以使用数据集向Gridview列添加变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集'ds1'来绑定Gridview1。

接下来,使用另一个数据集'ds21'我将值传递给变量'v_ProductName'。

现在我想将此v_ProductName添加到'ds1'并绑定Gridview1。我提交了我的代码:

I have a dataset 'ds1' to bind a Gridview1.
Next , with another dataset 'ds21' I pass a value to a variable 'v_ProductName'.
Now I want to add this v_ProductName to 'ds1' and bind Gridview1. I submit my code:

<asp:BoundField DataField="tx_id" HeaderText="Tx Id" />
  <asp:BoundField DataField="ProductId" HeaderText="Produc Id" />
  <asp:BoundField DataField="ProductName" HeaderText="Produc Id" />
  <asp:BoundField DataField="OrderQty" HeaderText="Ordered Qty" />
  <asp:BoundField DataField="CostOnDateOfOrder" HeaderText="Rate" />
  <asp:BoundField DataField="AmountDue" HeaderText="Amount due " />




List<string> adds1 = new List<string>();
                        SqlDataAdapter da1 = new SqlDataAdapter("select tx_id,ProductId,OrderQty,CostOnDateOfOrder,AmountDue from txfile where CartTxNo='" + v_CartTxNo + "'", con);
                        SqlCommandBuilder cb21 = new SqlCommandBuilder(da1);
                        DataSet ds1 = new DataSet("carttxno");
                        da1.Fill(ds1, "carttxno");
                        for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                        {
                           adds1.Add(ds1.Tables[0].Rows[i].ItemArray[0].ToString());
                           v_ProductId=ds1.Tables[0].Rows[i]["ProductId"].ToString();
                           List<string> adds2 = new List<string>();
                           SqlDataAdapter da2 = new SqlDataAdapter("select ProductName from product where ProductId='" + v_ProductId + "'", con);
                           SqlCommandBuilder cb221 = new SqlCommandBuilder(da2);
                           DataSet ds21 = new DataSet("productname");
                           da2.Fill(ds21, "productname");
                           for (int ii = 0; ii < ds21.Tables[0].Rows.Count; ii++)
                           {
                           v_ProductName = ds21.Tables[0].Rows[ii]["ProductName"].ToString();
                           }

                        }
                       GridView1.DataSource = ds1;
                       GridView1.DataBind();
                       GridView1.Visible = true;

推荐答案

嗯这种情况你必须这样做



Well In this Kind Of Case You Have To Do Like This

for (int ii = 0; ii < ds21.Tables[0].Rows.Count; ii++)
{
v_ProductName = ds21.Tables[0].Rows[ii]["ProductName"].ToString();
gridview1.Rows[ii].Cells[ColumnIndexThat].innerHTML=v_ProductName;
}





好​​吧我没试过但我觉得应该可以工作



如果你在Datagrid的数据源中使用Join Query来远离这个复杂的编码,我想给你一个建议,那将会更好



Well I didn't Try It But I Think It Should Work

And I Want To Give You one Advise to That That It Will Be Better If You Do use Of Join Query in Datagrid`s datasource to stay far from this complex coding


这篇关于我可以使用数据集向Gridview列添加变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆