开发者

Asp repeater accessing each line from an sql datasource

开发者 https://www.devze.com 2023-03-31 07:23 出处:网络
I have a repeater that on itemdatabound i want to access the row in the sqldatasource so i can get the id of an item.

I have a repeater that on itemdatabound i want to access the row in the sqldatasource so i can get the id of an item.

I cant use hidden fields to do this so are there any other options? Than开发者_JS百科ks to all


You can try something like this in the ItemDataBound event:

if (Repeater1.DataSource != null)
{
    int ID = ((DataTable)Repeater1.DataSource).Rows[e.Item.ItemIndex].Field<int>("ID");
}

Or this might work too:

int ID = (int)((DataRowView)e.Item.DataItem)["ID"];


In ItemDataBound try:

((DataRowView)e.Item.DataItem)["YourKey"] 

DataItem is your bound item, be it a custom class or a data row for example. This depends on how you are binding it but you didn't specify.

0

精彩评论

暂无评论...
验证码 换一张
取 消