1.在Repeater_ItemDataBound事件中设置按钮的CommandArgument。代码如下:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView dv = (DataRowView)e.Item.DataItem;
((LinkButton)e.Item.FindControl("editBtn")).CommandArgument = dv.Row["ID"].ToString() + "$" + e.Item.ItemIndex.ToString();
((LinkButton)e.Item.FindControl("delBtn")).CommandArgument = dv.Row["ID"].ToString() + "$" + e.Item.ItemIndex.ToString();
}
{
DataRowView dv = (DataRowView)e.Item.DataItem;
((LinkButton)e.Item.FindControl("editBtn")).CommandArgument = dv.Row["ID"].ToString() + "$" + e.Item.ItemIndex.ToString();
((LinkButton)e.Item.FindControl("delBtn")).CommandArgument = dv.Row["ID"].ToString() + "$" + e.Item.ItemIndex.ToString();
}
2.在Repeater_ItemCommand事件中获取值,代码如下:
if (e.CommandName == "edt")
{
string[] ca = e.CommandArgument.ToString().Split('$');
int itemIndex = Convert.ToInt32(ca[1]);
TextBox ClassTitleTextBox = this.Repeater1.Items[itemIndex].FindControl("ClassTitle") as TextBox;
string ClassTitle = ClassTitleTextBox.Text;
}
{
string[] ca = e.CommandArgument.ToString().Split('$');
int itemIndex = Convert.ToInt32(ca[1]);
TextBox ClassTitleTextBox = this.Repeater1.Items[itemIndex].FindControl("ClassTitle") as TextBox;
string ClassTitle = ClassTitleTextBox.Text;
}