1
在我的SQL查詢中,我檢索3個字符串,第三個字符串有一個URL。我創建了2個templatefield包含標籤和另一個模板與圖像。現在我想將值設置爲兩個標籤,並通過設置ImageUrl來查看圖像並顯示從SQL查詢中出來的所有行。如何將數據從sql查詢設置到gridview模板字段
protected void Page_Load(object sender, EventArgs e)
{
//if (IsPostBack == false)
//{
// grdMaterial.DataBind();
//}
try
{
matType = int.Parse(Session["mattype"].ToString());
colorId = int.Parse(Session["color"].ToString());
matStyleId = int.Parse(Session["matstyle"].ToString());
try
{
matContent = Session["matContent"].ToString();
}
catch
{
panAval.Visible = true;
panNew.Visible = false;
dtab = new DBHELPER().getdataTable("SELECT [item_Id],[mat_Content],[mat_Image] FROM [item] WHERE [mat_Content]='" + matContent + "'");
//grdMaterial.DataSource = dtab;
//grdMaterial.DataBind();
}
catch (Exception ee)
{
}
}
protected void grdMaterial_Load(object sender, EventArgs e)
{
try
{
for (int i = 0; i < dtab.Rows.Count; i++)
{
//TextBox x = (TextBox)GridViewCarrinho.Rows[row.RowIndex].Cells[2].FindControl("txtQuantidade");
Label itemId = (Label)grdMaterial.FindControl("lblItemId");
itemId.Text = dtab.Rows[i]["item_Id"].ToString();
Label matContent = (Label)grdMaterial.FindControl("lblItemName");
matContent.Text = dtab.Rows[i]["mat_Content"].ToString();
Image itemImage = (Image)grdMaterial.FindControl("imgItemImage");
itemImage.ImageUrl = dtab.Rows[i]["mat_Image"].ToString();
}
}
catch (Exception ee)
{
}
}
哇。您已將實際問題發佈在標題中。標題用來用幾個字來描述問題。看看別人如何提出問題。 – shahkalpesh 2009-09-10 21:35:01