GridView RowCommand不会触发 [英] GridView RowCommand Not Firing
问题描述
我无法弄清楚为什么RowCommand没有触发。奇怪的是,我在页面上有一个不同的GridView,它的RowCommand没有问题,所以我不知道这个问题会发生什么。
我有以下代码:
JavaScript
function displayPayees ){
$('#payeeList')。css(display,block);
$('#payeeList')。dialog({
modal:true,
draggable:false,
resizable:false,
maxHeight:600,
width:800,
position:{my:center top,at:center top + 15%,of:window}
});
}
.aspx页面 p>
< div id =payeeListtitle =Available Payeesstyle =display:none;>
< asp:GridView ID =gvPayeesrunat =serverVisible =trueAutoGenerateColumns =falseShowHeaderWhenEmpty =trueWidth =100%AllowSorting =TrueOnRowCommand =gvPayees_RowCommand CssClass =table table-striped>
< HeaderStyle Font-Bold =TrueForeColor =WhiteHeight =15pxBackColor =#46596bWrap =False>< / HeaderStyle>
<列>
< asp:BoundField DataField =TaxIDHeaderText =Tax ID>< / asp:BoundField>
< asp:BoundField DataField =NameHeaderText =Name>< / asp:BoundField>
< asp:BoundField DataField =Address1HeaderText =Address>< / asp:BoundField>
< asp:BoundField DataField =Address2HeaderText =Address 2>< / asp:BoundField>
< asp:BoundField DataField =CityHeaderText =City>< / asp:BoundField>
< asp:BoundField DataField =StateHeaderText =State>< / asp:BoundField>
< asp:BoundField DataField =ZipHeaderText =Zip>< / asp:BoundField>
< asp:TemplateField HeaderText =>
< ItemStyle HorizontalAlign =CenterVerticalAlign =Middle/>
< ItemTemplate>
< asp:Button ID =btnSelectPayeerunat =serverText =SelectCssClass =btn btn -default home-btn btn-smCausesValidation =falseCommandName =SelectPayeeCommandArgument = '<%#Eval(TaxID)& 〜& Eval(Name)& 〜& Eval(Address1)& 〜& Eval(Address2)& 〜& Eval(城市)& 〜& Eval(State)& 〜& Eval(Zip)%>'/>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>
< / div>
后面的代码
Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load
如果不是Page.IsPostBack然后
BindDetails()
End If
End Sub
受保护的子gvPayees_RowCommand(ByVal sender As Object,ByVal e As GridViewCommandEventArgs)
抛出新异常(Hello?)'测试码
End Sub
更新: $ b
我注意到将GridView移出它包含 div
会导致RowCommand正确触发。
我使用
I'm having trouble figuring out why the RowCommand isn't firing. Oddly enough, I have a different GridView on the page and its RowCommand is firing without issue so I have no idea what the problem could be.
I have the following code:
JavaScript
function displayPayees() {
$('#payeeList').css("display", "block");
$('#payeeList').dialog({
modal: true,
draggable: false,
resizable: false,
maxHeight: 600,
width: 800,
position: { my: "center top", at: "center top+15%", of: window }
});
}
.aspx Page
<div id="payeeList" title="Available Payees" style="display:none;">
<asp:GridView ID="gvPayees" runat="server" Visible="true" AutoGenerateColumns="false" ShowHeaderWhenEmpty="true" Width="100%" AllowSorting="True" OnRowCommand="gvPayees_RowCommand" CssClass="table table-striped">
<HeaderStyle Font-Bold="True" ForeColor="White" Height="15px" BackColor="#46596b" Wrap="False"></HeaderStyle>
<Columns>
<asp:BoundField DataField="TaxID" HeaderText="Tax ID"></asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name"></asp:BoundField>
<asp:BoundField DataField="Address1" HeaderText="Address"></asp:BoundField>
<asp:BoundField DataField="Address2" HeaderText="Address 2"></asp:BoundField>
<asp:BoundField DataField="City" HeaderText="City"></asp:BoundField>
<asp:BoundField DataField="State" HeaderText="State"></asp:BoundField>
<asp:BoundField DataField="Zip" HeaderText="Zip"></asp:BoundField>
<asp:TemplateField HeaderText="">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Button ID="btnSelectPayee" runat="server" Text="Select" CssClass="btn btn-default home-btn btn-sm" CausesValidation="false" CommandName="SelectPayee" CommandArgument='<%# Eval("TaxID") & "~" & Eval("Name") & "~" & Eval("Address1") & "~" & Eval("Address2") & "~" & Eval("City") & "~" & Eval("State") & "~" & Eval("Zip") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Code Behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindDetails()
End If
End Sub
Protected Sub gvPayees_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Throw New Exception("Hello?") 'Test code
End Sub
UPDATE:
I noticed that moving the GridView out of it's containing div
causes the RowCommand to fire properly.
I'm using jQuery UI to put the GridView into a dialog box to be displayed on a button click. I have display: none
on the containing div
so that the GridView is invisible until the button click and I think that may be the source of my problem. I'm updating my code here to reflect that.
How can I hide the div
until button click without preventing the RowCommand from firing properly?
Change it from a Button
to a LinkButton
and it will work.
<ItemTemplate>
<asp:LinkButton ID="btnSelectPayee" runat="server" CommandName="SelectPayee" CommandArgument='<%# Eval("TaxID") %>' >Select</asp:LinkButton>
</ItemTemplate>
Apparently the jQuery UI dialog places the modal outside the </form>
tag, so normal buttons don't work anymore. But LinkButtons use JavaScript to perform the PostBack, and they are still registered within the framework.
这篇关于GridView RowCommand不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!