我有一个 DataGridView,它有两个动态生成的 ItemTemplate 按钮列。我为单击它们时触发的两个按钮提供了代码隐藏,但是当单击 btnInfo 按钮时,我还需要一个 javascript 函数来运行
标记:
<asp:GridView ID="gridResutls" runat="server" OnRowCommand="gridResutls_RowCommand" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="strName" HeaderText="Name"/>
<asp:BoundField DataField="strBrand" HeaderText="Brand"/>
<asp:BoundField DataField="strServing" HeaderText="Serving"/>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnInfo" runat="server" CausesValidation="false" CommandName="MoreInfo"
Text="More Info" CommandArgument='<%# Eval("strID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnAdd" runat="server" CausesValidation="false" CommandName="AddItem"
Text="Add To Log" CommandArgument='<%# Eval("strID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>'
我有一个调用populateLabel()
btnInfo 时需要触发的 javascript 函数。
有任何想法吗?(我知道有人问过类似的问题,我查看了所有帖子并尝试了一些东西,但似乎没有任何效果)
编辑:这是 ItemTemplate 按钮的代码隐藏的样子
protected void gridResutls_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
// Kick out if neither of the two dynamically created buttons have been clicked
if (e.CommandName != "MoreInfo" && e.CommandName != "AddItem")
{
return;
}
// If the "More Info" buton has been clicked
if (e.CommandName == "MoreInfo")
{
// Some code
}
// If the "Add To Log" button has been clicked
if (e.CommandName == "AddItem")
{
// Some code
}
}