首页 新闻 会员 周边 捐助

ListView中嵌套GridView,在线急等!

0
悬赏园豆:15 [待解决问题]

小弟在做一个订单的处理,一张订单表和一张订单明细表。同时显示订单表订单表和订单明细表的内容,让GridView显示订单明细表中对应订单表的相同订单ID内容。

前段代码:

<asp:ListView ID="lv" runat="server" DataKeyNames="OrderId">
            <LayoutTemplate>
                <table id="Table1" runat="server" border="0">
                    <tr runat="server" id="itemPlaceHolder"></tr>
                </table>
            </LayoutTemplate>

            <ItemTemplate>
                    <tr>
                        <td>
                            <table>
                            <tr><td>订单号:</td><td><asp:Label ID="lblId" runat="server" Text='<%Bind("OrderId") %>'></asp:Label></td></tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                    <td>
                        <table >
                            <tr>
                                <td>
                                    <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" DataSource='<%# GVSource() %>'>
                                        <Columns>
                                            <asp:BoundField DataField="GoodsName" HeaderText="商品名" />
                                            <asp:BoundField DataField="Price" HeaderText="价格" />
                                            <asp:BoundField DataField="Quantity" HeaderText="数量" />
                                        </Columns>
                                    </asp:GridView>
                                </td>
                            </tr>
                        </table>
                    </td>
               </tr>

后台代码:

public object GVSource()
        {
            LQDataClassesDataContext lq = new LQDataClassesDataContext(ConfigurationManager.ConnectionStrings["db_B2CConnectionString"].ConnectionString);
            var result = from u in lq.tb_OrderDetails
                          join gds in lq.tb_Goods on u.GoodsId equals gds.GoodsId
                          where u.OrderId == lv.DataKeys[CurrentIndex].Value.ToString()
                          select new
                          {
                              GoodsName = gds.GoodsName,
                              Price = u.Price,
                              Quantity = u.Quantity,
                          };
            return result;
        }

就是如何能获得当前行的索引,就是CurrentIndex的位置要用的

好好学习V天天向上的主页 好好学习V天天向上 | 初学一级 | 园豆:185
提问于:2011-07-05 12:29
< >
分享
所有回答(2)
0

在GridView中设置DataKeys属性值,如DataKeys="订单ID"

 

后台则获取: DataKeys[0].Value.ToString()

小胆粗心 | 园豆:300 (菜鸟二级) | 2011-07-06 15:39
谢谢,我降低难度了!呵呵...
支持(0) 反对(0) 好好学习V天天向上 | 园豆:185 (初学一级) | 2011-07-07 16:56
0

找的,不知道是否可以帮你.

View Code
//ListView中数据绑定时 激发GridView绑定事件 
   protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
   {
   if (e.Item.ItemType == ListViewItemType.DataItem)
   {
  
  
   ((GridView)e.Item.FindControl("GridView1")).DataSource=getData((e.Item.FindControl("TextBox1") as TextBox).Text);
   ((GridView)e.Item.FindControl("GridView1")).DataBind();
  //绑定数据方法
   public DataTable getData(string rq)
   {
   Response.Write("<script>alert('" + rq + "')   //string sql = "select 项目 from HHR_月考核表 where 创建时间='"+rq+ "'";
   SqlDataAdapter da = new SqlDataAdapter("proc_任务提示框四", con);
   da.SelectCommand.CommandType = CommandType.StoredProcedure;
   SqlParameter p = new SqlParameter("@rq",DbType.DateTime);
   p.Value = Convert.ToDateTime(rq);
   da.SelectCommand.Parameters.Add(p);
   DataSet ds = new DataSet();
   da.Fill(ds,"tab");
   return ds.Tables["tab"];
  
  
   }
freedragon | 园豆:205 (菜鸟二级) | 2011-12-28 15:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册