您好我正在使用jquery移动应用程序并遇到Gridview rowcommand事件触发的问题。
这是我在aspx页面中的代码
<asp:GridView runat="server" ID="Grd_List" Width="100%" GridLines="none" AutoGenerateColumns="false" Style="margin-top: 0px;" OnRowCommand="Grd_List_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table data-role="table" id="table1" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive table1" data-column-btn-theme="c" data-column-popup-theme="c">
<thead>
<tr class="thead">
<th> </th>
<th>PC</th>
<th>QC</th>
</tr>
</thead>
<tr>
<td class="heading"><strong>Part #</strong></td>
<td><%# Eval("pn-pc") %></td>
<td><%# Eval("pn-qc") %></td>
</tr>
<tr>
<td class="heading"><strong>Closure Size</strong></td>
<td><%# Eval("xmlfile-pc") %></td>
<td><%# Eval("xmlfile-qc") %></td>
</tr>
<tr>
<td class="heading"><strong>Quantity per Case</strong></td>
<td>72</td>
<td>72</td>
</tr>
<tr>
<td class="heading"><strong>Price</strong></td>
<td><%# Eval("Price-pc", "{0:C}") %></td>
<td><%# Eval("Price-qc", "{0:C}") %></td>
</tr>
<tr>
<td><strong>Add to Cart</strong></td>
<td>
<asp:HiddenField runat="server" ID="xmlfile_PC" Value='<%# Eval("xmlfile-pc") %>' />
<asp:TextBox runat="server" ID="qty_pc" name="text-basic" Text="1"></asp:TextBox>
<asp:LinkButton runat="server" ID="btn_pc" CssClass="add-cart" CommandName="pc" CommandArgument='<%# Eval("id-pc") %>'><i class="add-to-cart-icon"></i>Add to Cart</asp:LinkButton>
</td>
<td>
<asp:HiddenField runat="server" ID="xmlfile_QC" Value='<%# Eval("xmlfile-qc") %>' />
<asp:TextBox runat="server" ID="qty_qc" Text="1"></asp:TextBox>
<asp:LinkButton runat="server" ID="btn_qc" CssClass="add-cart" CommandName="qc" CommandArgument='<%# Eval("id-qc") %>'><i class="add-to-cart-icon"></i>Add to Cart</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
以下是RowCommand事件代码背后的代码:
protected void Grd_List_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "pc")
{
GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int RowIndex = gvr.RowIndex;
int CatID = Convert.ToInt32(Request.QueryString["id"]);
TextBox txtqtyPC = Grd_List.Rows[RowIndex].FindControl("qty_pc") as TextBox;
HiddenField xmlfile = Grd_List.Rows[RowIndex].FindControl("xmlfile_PC") as HiddenField;
int qty = Convert.ToInt32(txtqtyPC.Text);
Response.Redirect("view-cart.aspx?qty=" + qty + "&prinfo=" + CatID + "^" + e.CommandArgument.ToString() + "^" + xmlfile.Value);
}
}
当我浏览我的应用程序时,此事件未触发.. 任何帮助? 感谢
答案 0 :(得分:0)
我认为你需要注册你甚至示例代码也检查属性onrowdatabound="gv_RowDataBound"
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Show Message
LinkButton lb = e.Row.FindControl("lnkBtnShowDetails") as LinkButton;
if (lb != null)
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
}