更新面板中的功能

时间:2011-08-14 07:32:34

标签: c# asp.net events gridview updatepanel

<asp:UpdatePanel ID="UpdatePanel10" runat="server">
        <ContentTemplate>
            <center>
                    <asp:GridView ID="gridInboxMessage" runat="server" AllowPaging="True"
                        AllowSorting="True" 
                        AutoGenerateColumns="False" DataSourceID="LinqDataSource1"                            OnSelectedIndexChanged="gridInboxMessage_SelectedIndexChanged"   
                        onrowdeleted="gridInboxMessage_RowDeleted" 
                        onrowdeleting="gridInboxMessage_RowDeleting">
                        <Columns>

                            <asp:CommandField ShowSelectButton="True"  SelectText="show text" />   

                           <asp:TemplateField >
                                <ItemTemplate>
                                    <asp:Button ID="btnDeleteInbox" Text="delete" OnClick="btnDeleteInbox_Click" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:BoundField DataField="Row" HeaderText="row" ReadOnly="True" SortExpression="Row" />

                            <asp:TemplateField SortExpression="Body" HeaderText="متن">
                                <ItemTemplate>
                                    <asp:Label ID="MyBody" runat="server" Text='<%# TruncateText(Eval("Body"))%>'>                            
                                    </asp:Label>
                                    <asp:Label ID="fullBodyRecieve" Visible="false" runat="server" Text='<%# Eval("Body")%>'>
                                    </asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>                               
                        </Columns>
                    </asp:GridView>

                    <asp:LinqDataSource  ID="LinqDataSource1" AutoSort="true" 
                         runat="server" ContextTypeName="DataClassesDataContext"
                        Select="new (Row,Title, Body, Sender, Date1)" TableName="PrivateMessages" 
                        Where="Receptor == @Receptor" ondeleted="LinqDataSource1_Deleted" 
                        ondeleting="LinqDataSource1_Deleting">
                        <WhereParameters>
                            <asp:QueryStringParameter Name="Receptor" QueryStringField="idCompany" Type="String" />
                        </WhereParameters>
                    </asp:LinqDataSource>
        </ContentTemplate>

    </asp:UpdatePanel>

 protected void btnDeleteInbox_Click(object sender, EventArgs e)
{
    GridViewRow row = gridInboxMessage.SelectedRow;
    var inboxMessage = (from b in dc.PrivateMessages where b.Row.ToString() ==     row.Cells[0].Text select b).Single();
    dc.PrivateMessages.DeleteOnSubmit(inboxMessage);
    dc.SubmitChanges();
}

btnDeleteInbox_Click不起作用?永远不会执行此方法

protected void gridInboxMessage_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
    GridViewRow row = gridInboxMessage.SelectedRow;
    var inboxMessage = (from b in dc.PrivateMessages where b.Row.ToString() == row.Cells[0].Text select b).Single();
    dc.PrivateMessages.DeleteOnSubmit(inboxMessage);
    dc.SubmitChanges();
}

gridInboxMessage_RowDeleted不起作用?永远不会执行此方法

protected void gridInboxMessage_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    GridViewRow row = gridInboxMessage.SelectedRow;
    var inboxMessage = (from b in dc.PrivateMessages where b.Row.ToString() == row.Cells[0].Text select b).Single();
    dc.PrivateMessages.DeleteOnSubmit(inboxMessage);
    dc.SubmitChanges();
}

gridInboxMessage_RowDeleting不起作用?永远不会执行此方法

1 个答案:

答案 0 :(得分:0)

RowDeleted和RowDeleting事件处理程序可能没有被执行,因为它看起来好像没有任何东西正在调用delete命令。您没有生成删除按钮,而您的自定义按钮未调用删除命令。请参阅RowDeleting事件文档中的示例,了解如何实现事件的使用。请注意,该示例设置了&#34; AutoGenerateDeleteButton&#34;财产到真。当用户单击该按钮时,将触发RowDeleting和RowDeleted事件。

我不确定为什么你的自定义按钮的处理程序没有被执行。你能否确认你的网页确实在回帖?您是否能够通过代码进行调试以查看回发期间采取的步骤?正如穆罕默德所要求的,您能否包括您的页面加载代码以及任何其他相关代码?