开发者

functions in update panel

开发者 https://www.devze.com 2023-03-27 19:33 出处:网络
<asp:UpdatePanel ID=\"UpdatePanel10\" runat=\"server\"> <ContentTemplate> <center> <asp:GridView ID=\"gridInboxMessage\" runat=\"server\" AllowPaging=\"True\"
<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 doe not work??This method is never executed

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 doe not work??This method is never executed

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 doe not work??This method is never executed


The RowDeleted and RowDeleting event handlers are probably not getting executed because it does not appear as though anything is calling the delete command. You're not generating a delete button and your custom button is not calling the delete command. See the example in the RowDeleting event documentation for how to implement the use of the event. Notice that the example sets the "AutoGenerateDeleteButton" property to true. When they user clicks that button, the RowDeleting and then RowDeleted events will fire.

I'm not sure why your custom button's handler is not getting executed. Can you confirm that your page is indeed posting back? Are you able to debug through the code to see what steps it is taking during the postback? As Muhammad requested, will you please include your page load code as well as any other relevant code?

0

精彩评论

暂无评论...
验证码 换一张
取 消