HTML CODE,这个概念可以工作,但我需要在数据绑定后将它应用到我的gridview表上。
$(document).ready(function () {
$('.clickme').click(function() {
alert("Hello World");
});
});
<tr class="clickme">
<td>Shop: </td>
</tr>
<asp:GridView ID="dgMain" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ChassisNo" OnPageIndexChanging="dgMain_PageIndexChanging"
OnRowCreated = "OnRowCreated" CssClass="table table-bordered" CellPadding="6" HeaderStyle-BackColor="#eeeeee" OnSorting="Sorting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="chkSelection" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No" >
<ItemTemplate>
<asp:Label id="LabelNo" runat="server" >
<%# GetIndex( DataBinder.Eval(Container, "RowIndex")) %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OperationName" HeaderText="Operation Name" SortExpression="OperationName"/>
<asp:BoundField DataField="OperationStart" HeaderText="Operation Start" SortExpression="OperationStart"/>
<asp:BoundField DataField="LOTNo" HeaderText="LOT No" SortExpression="LOTNo"/>
<asp:BoundField DataField="MSC" HeaderText="MSC" SortExpression="MSC" />
<asp:BoundField DataField="MaterialGroup" HeaderText="Material Group" SortExpression="MaterialGroup"/>
<asp:BoundField DataField="ChassisNo" HeaderText="Chassis No" SortExpression="ChassisNo" />
<asp:BoundField DataField="ColorID" HeaderText="Color ID" SortExpression="ColorID"/>
</Columns>
<PagerStyle HorizontalAlign="Center" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
我想点击下面的row1图,然后会提示消息Hello world, 如果我点击Row2,它将显示helloworld2。
__________________________________________________________________
|___Row1__________|_____Row1____|_______Row1_____|_____Row1________|
|___Row2__________|_____Row2____|_______Row2_____|_____Row2________|
|___Row3__________|_____Row3____|_______Row3_____|_____Row3________|
|___Row4__________|_____Row4____|_______Row4_____|_____Row4________|
答案 0 :(得分:0)
如果你想用rowNumber显示警告,那么它就是这么简单 使用
onrowdatabound =“CustomersGridView_RowDataBound”for gridview
<asp:gridview id="CustomersGridView"
autogeneratecolumns="true"
allowpaging="true"
onrowdatabound="CustomersGridView_RowDataBound"
runat="server">
</asp:gridview>
和服务器端
public void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "alert('helloworld " + e.Row.RowIndex + "')");
}
}