GridView怎么能实现 横向绑定数据。要绑定TextBox ,因为数据需要有修改更新功能。不能用DataTable..
有其他解决方案吗?十分感谢!

解决方案 »

  1.   

    GridView自带修改更新功能的吧
      

  2.   

    参考
    http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
      

  3.   

    横向绑定DataList不是很好吗???为啥非要使用GridView呢》
    微软之所以提供多种控件,就是满足不同需求来的,不同的需求采用合适的控件,而不是的都去采用GridView
      

  4.   

    是的,现在datalist用的也不是很多,以repeater为主,样式完全按自己的需求来,很灵活。
      

  5.   

    行转列
    http://topic.csdn.net/u/20090210/10/25a079f8-1480-48e6-be29-6da3e97cfda3.html
      

  6.   

    GridView的布局已经固定了,你可以用DataList控件,然后在里面写HTML代码,想怎么布局就怎么布局,然后用Eval或DataBinder.Eval方法绑定数据。
      

  7.   

    这是我做的一个例子
     前台:
    <asp:GridView>
       <Columns>
          <asp:TemplateField HeaderText="数量">
                                <ItemTemplate>
                                    <asp:TextBox ID ="textbox1" runat="server"  Text='<%#Eval("Quantity")%>'>
                                    </asp:TextBox>
                                </ItemTemplate>
     </asp:TemplateField><asp:ButtonField HeaderText="更新" Text="更新"   CommandName="update" />
      </Columns>
    </asp:GridView>
    后台:
      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
           //获取textbox中要更新的数量
            int quantity = Convert.ToInt32(((TextBox)(GridView1.Rows[e.RowIndex].FindControl("textbox1"))).Text);
           
                //获取数据库连接字符串
                string strconn = ConfigurationManager.ConnectionStrings["connectionStr"].ToString();
                //连接数据库
                SqlConnection conn = new SqlConnection(strconn);
                conn.Open();
                string strsql = "update CartInfo set Quantity='" + quantity + "' where Name='"
                    + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
                SqlCommand cmd = new SqlCommand(strsql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                GridView1.EditIndex = -1;
                //更新后绑定数据
                bind();
           
        }