dynamically generated html buttons: source of onclick event caller
I have a DataTable which has a column like such:
string temp = row["date"].ToString();
rowDetail[0] = "<input type='button' onclick='showArchive(this)' value='" + temp + "'/>";
myTbl.Rows.Add(rowDetail);
So, when I bind myTbl to a datagrid.datasource, these column cells appear as buttons display "date" data. However, in my javascript function where the onclick event takes place, how would I know button/row made the call, so I can grab the rest of th开发者_StackOverflow社区e data in that row for processing? I hope that's not lacking too much detail. Thanks all
Edit: Here's my js event:
function showArchive(btn)
{
__doPostBack('btnShowDates', '/*btn.gridRowIndex*/');
}
Something like this would be ideal lol.
You can do this in pure JavaScript, but is is much easier if you use jQuery. This will give you the row data, assuming you're using a table:
function showArchive(element) {
var myRow = $(element).parents('tr')
$(myRow).find('td').each(function() {
alert($(this).html())
})
}
精彩评论