GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowIndex > -1)
        {
            dataclass dclass = new dataclass();
            #region 控件查找 读取值
            DataList dt = (DataList)e.Row.FindControl("datalist2");
            DataRowView row = (DataRowView)e.Row.DataItem;
            string mainID = row["partno"].ToString();
          
            string sqll = "select photo from tablingshi where partno='" + mainID + "'";
          
            #endregion
           ??? DataRow dr = dclass.dt(sqll, "srt").Rows[0];
           ???? Response.Write(dr[0]);
           ???? Response.End();
           
            #region 定义数组            string s = dr[0].ToString();
            Int32 t = s.Split(',').Length;
            string[] arrary = s.Split(',');            #endregion            #region 手动绑定内层的DATALIST            DataTable table = new DataTable();
            DataColumn column;
            DataRow rw;
            column = new DataColumn();
            column.DataType = Type.GetType("System.String");
            column.ColumnName = "name";
            table.Columns.Add(column);
            for (int i = 0; i < t; i++)
            {
                rw = table.NewRow();
                rw["name"] = arrary[i];
                table.Rows.Add(rw);
                Response.Write(arrary[0]);
               Response.End();            }            dt.DataSource = table;
            dt.DataBind();            #endregion
        }    }代码如上 ???这里怎么不执行哦 ???

解决方案 »

  1.   

    dataclass(); public DataTable dt(string mysql,string tb)
        {
            DataSet ds = this.ds(mysql, tb);
            DataTable dtable = ds.Tables[tb];
            return dtable;
         }
      

  2.   

    做法不对,要找到控件,最起码要protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        { 
        //在这里你的操作
        }
    }
      

  3.   

    比较简单的做法
    <asp:GridView ID="GridView1" runat="server" DataSourceID="sdsProducts" AutoGenerateColumns="False" DataKeyNames="productid" >  
        <Columns>
            <asp:BoundField DataField="productName" /> 
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:DataList ID="DataList1" runat="server" DataSource='<%# GetPicture(Convert.ToInt32(Eval("productid"))) %>'>
                        <ItemTemplate>
                            <img src='<%# Container.DataItem %>' />
                        </ItemTemplate>
                    </asp:DataList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns> 
    </asp:GridView> <asp:SqlDataSource ID="sdsProducts" runat="server" ConnectionString="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="select top 5 * from products" >
    </asp:SqlDataSource>protected string []  GetPicture(int productid)

        //这里你应该根据你的id进行查询,返回一个string数组就可以了
        string [] str = new string[]{"1.jpg","2.jpg","3.jpg"};
        return str;
    }