ItemDataBound C#ASP.net上的方法用法
本文关键字:方法 用法 C#ASP net ItemDataBound | 更新日期: 2023-09-27 17:58:58
我有一个方法可以在ItemDataBound上使用;
static void getPhoto() {
Fonksiyonlar vt=new Fonksiyonlar();
DataTable SeriFoto = vt.GetDataTable("select foto from seriFotograf where seriilanID=" + DataBinder.Eval(e.Item.DataItem, "ilan_id") + " and kapak=true" + " order by seriilanID desc");
if (SeriFoto.Rows.Count < 1)
{
DataRow nullPhotoRow;
nullPhotoRow = SeriFoto.NewRow();
nullPhotoRow["foto"] = "0.png";
SeriFoto.Rows.Add(nullPhotoRow);
}
Repeater rptReddedilenFoto = (Repeater)e.Item.FindControl("rptReddedilenFoto");
rptReddedilenFoto.DataSource = SeriFoto;
rptReddedilenFoto.DataBind();
}
但是我得到一个错误:
名称"e"在当前上下文中不存在
这些代码运行正常,但它不在方法中。
最简单的方法是,将DataGridItem
传递给此方法(如果是GridView,则传递GridViewRow
):
static void getPhoto(DataGridItem item) {
DataRowView view = (DataRowView) item.DataItem;
Fonksiyonlar vt=new Fonksiyonlar();
DataTable SeriFoto = vt.GetDataTable("select foto from seriFotograf where seriilanID=" + view["ilan_id"] + " and kapak=true" + " order by seriilanID desc");
if (SeriFoto.Rows.Count < 1)
{
DataRow nullPhotoRow = SeriFoto.NewRow();
nullPhotoRow["foto"] = "0.png";
SeriFoto.Rows.Add(nullPhotoRow);
}
Repeater rptReddedilenFoto = (Repeater)item.FindControl("rptReddedilenFoto");
rptReddedilenFoto.DataSource = SeriFoto;
rptReddedilenFoto.DataBind();
}