gridview 嵌套datalist问题
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
}
}
代码如上 ???这里怎么不执行哦 ???
------解决方案--------------------
做法不对,要找到控件,最起码要
C# code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//在这里你的操作
}
}