Stop double reverse gear

That's what I'm doing. I create two buttons in the gridview title bar that I created. Buttons + page and -page. When the page-page is deleted, I delete the paging, and all the data falls onto the page, and the page disappears and the + page.

My problem comes . When I click the page, I have to be double relay because one line of my data disappears. I will provide the code below. What can I do to fix this?

Dim bttnrempag As New Button
    bttnrempag.ID = "bttnrempag"
    bttnrempag.Text = "      Paging"
    bttnrempag.CssClass = "bttnMinEG"
    bttnrempag.ValidationGroup = "alone"
    bttnrempag.Attributes.Add("onclick", "return Paging('1')")

    Dim bttnallowpag As New Button
    bttnallowpag.ID = "bttnallowpag"
    bttnallowpag.Text = "      Paging"
    bttnallowpag.ValidationGroup = "alone"
    bttnallowpag.CssClass = "bttnAddEG"
    bttnallowpag.Attributes.Add("onclick", "return Paging('0')")

--------------------- How to add buttons ------------------ -------- ----------------

    Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
    row.Cells.Add(cell)
    cell.Controls.Add(bttnrempag) '36
    cell.Controls.Add(bttnallowpag)

-------------------------------------------- ------ --------------------------------------

function Paging(remove) {
    var gridView = $get('<%=Gridview1.ClientID %>');
    var txt2 = $get('<%=TextBox2.ClientID %>');
    if (remove == '1') {
        txt2.value = '1';
        __doPostBack('<%=UpdatePanel1.ClientID %>', '');
        return false;
    }
    else {
        txt2.value = '0';
        __doPostBack('<%=UpdatePanel1.ClientID %>', '');
        return false;
    }

Edited

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate >
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            DataSourceID="SqlDataSource1" Font-Names="Comic Sans MS" Font-Size="XX-Small"
            Caption = '<table border="" width="100%" cellpadding="3" cellspacing="0" bgcolor="#4A3C8C"><tr><td style = "font-size:X-large;font-family:Arial CE;color:White"><b>Ordering/Receiving Log</u></td></tr></table>' 
            Font-Bold="True" PageSize="15" >
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

            <Columns>
                      Bound Data
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <EmptyDataTemplate>
            <head>
                <meta http-equiv="refresh" content="5;URL=/Corporate_newpo/ReceivingLog.aspx?">
            </head>
                <script type="text/javascript" >
                    var count = 6;
                    var counter = setInterval("timer()", 1000); //1000 will  run it every 1 second

                    function timer() {
                        count = count - 1;
                        if (count <= 0) {
                            clearInterval(counter);
                            //counter ended, do something here
                            return;
                        }
                        $get("timer").innerHTML = "The Table will Reload in " + count + " secs";
                    }
                </script>
                <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" 
                    ForeColor="#993333" Text="No Data was Found for the Selected Filter"></asp:Label><br /><br />
               <span id="timer" style="font-size:medium;color:blue"></span>
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />
            <PagerTemplate>
                <small 12px""="" style="font-size:xx-small; padding-right">Go To Page</small>
                <asp:DropDownList ID="ddlPageSelector" runat="server" AutoPostBack="true" 
                    Font-Size="XX-Small" Height="19px" Width="36px">
                </asp:DropDownList>
                <asp:ImageButton ID="btnFirst" runat="server" CommandArgument="First" 
                    CommandName="Page" SkinID="pagefirst" />
                <asp:ImageButton ID="btnPrevious" runat="server" CommandArgument="Prev" 
                    CommandName="Page" SkinID="pageprev" />
                <asp:ImageButton ID="btnNext" runat="server" CommandArgument="Next" 
                    CommandName="Page" SkinID="pagenext" />
                <asp:ImageButton ID="btnLast" runat="server" CommandArgument="Last" 
                    CommandName="Page" SkinID="pagelast" />
            </PagerTemplate>
            </asp:GridView>
        </ContentTemplate> 
    </asp:UpdatePanel>

, , , , Gridview, .

+3
7

, . , , .

using System.Linq;

private void GridView_OnItemDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var buttons = e.Row.Cells.OfType<DataControlFieldCell>().SelectMany(item => item.Controls.OfType<ImageButton>());
        foreach (ImageButton imageButton in buttons)
        {
            var argument = imageButton.CommandName + "$" + imageButton.CommandArgument;
            imageButton.OnClientClick = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView, argument) + "; return false;";
        }
    }
}
0

, "__doPostBack". Async, , . , .

+2

Click RowDataBound?

.

+1

< asp: ImageButtons > HTML <img> .

, . . - , . <img> src, , , . <img> , .

( ), , . , < asp: ImageButtons > <img> javascript click, , Paging().

- , < asp: ImageButton > onclick : ( " ?" ); , confirm() false, false , Paging() __doPostBack, .

+1

html, :

,

<img src=""/>

, ...

, ,

<asp:ImageButton ImageUrl="~/Images/blank.gif"...>

, Immediate Window, Page_Load ,

Page.Request.Params["__EVENTTARGET"];
+1

( , javascript):

bttnrempag.onclick += bttnrempag_Click; 

protected void bttnrempag_Click(object sender, EventArgs e)
{
    //handle the removal of paging or whatever.
}
0

ImageButtons. HTML <img src="">, , . .

0
source

Source: https://habr.com/ru/post/1717934/


All Articles