2

使用 asp.net 和带有寻呼机的 gridview 控件。

如何向它添加 onclientclick,以便它只会在 onclientclick 返回 true 时分页。

这是否可能,因为它可以通过链接完成?

我知道我能做到

GridView 寻呼机页面按钮可访问性

myGridView.Attributes.Add("onClick", "setOKToClose();") 但它将它添加到网格中,我希望它只添加到寻呼机

谢谢

4

3 回答 3

0

将您的寻呼机转换为模板,但您必须制定自己的逻辑来显示和管理页面索引。

这里有一个示例代码

    <PagerTemplate>
                        <asp:Panel ID="gvpanel" runat="server">
                            <table cellpadding="3" cellspacing="3" class="style4">
                                <tr>
                                    <td width="20%">
                                        <asp:Label ID="Label4" runat="server" CssClass="lb" Text="Page "></asp:Label>
                                        <asp:DropDownList ID="ddpage" runat="server" AutoPostBack="True" CssClass="txt" 
                                            onselectedindexchanged="ddpage_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <asp:Label ID="Label5" runat="server" CssClass="lb" Text="of "></asp:Label>
                                        <asp:Label ID="lbltot" runat="server" CssClass="lb" Text="0"></asp:Label>
                                    </td>
                                    <td width="60%">
                                        <table class="style1">
                                            <tr>
                                                <td width="15%">
                                                    <asp:LinkButton ID="lbp10" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lbp10_Click">Previous 10</asp:LinkButton>
                                                </td>
                                                <td width="15%">
                                                    <asp:LinkButton ID="lbp" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lbp_Click">Previous</asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb1" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">1 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb2" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">2 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb3" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">3  </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb4" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">4 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb5" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">5 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb6" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">6 </asp:LinkButton>
                                                </td>
                                                <td >
                                                    <asp:LinkButton ID="lb7" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">7 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb8" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">8 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb9" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">9 </asp:LinkButton>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="lb10" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lb1_Click">10</asp:LinkButton>
                                                </td>
                                                <td width="15%">
                                                    <asp:LinkButton ID="lbn" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lbn_Click">Next</asp:LinkButton>
                                                </td>
                                                <td width="15%">
                                                    <asp:LinkButton ID="lbn10" runat="server" CssClass="smalllinkbuttonf" 
                                                        Enabled="False" onclick="lbn10_Click">Next 10</asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                    <td width="20%">
                                        &nbsp;</td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </PagerTemplate>

这是c#代码

        protected void lbp10_Click(object sender, EventArgs e)
{
    GridView1.PageIndex = (GridView1.PageIndex - 10);
    bind();
}
protected void lbp_Click(object sender, EventArgs e)
{
    GridView1.PageIndex = (GridView1.PageIndex - 1);
    bind();
}
protected void lbn_Click(object sender, EventArgs e)
{
    GridView1.PageIndex = (GridView1.PageIndex + 1);
    bind();
}
protected void lbn10_Click(object sender, EventArgs e)
{
    GridView1.PageIndex = (GridView1.PageIndex + 10);
    bind();
}
protected void lb1_Click(object sender, EventArgs e)
{
    LinkButton lb = (LinkButton)sender;
    GridView1.PageIndex = (int.Parse(lb.Text) - 1);
    bind();
}

创建页脚的代码

     void addfooter(int rcount)
{
    if (GridView1.BottomPagerRow == null)
    {
        return;
    }
    Panel p = (Panel)GridView1.BottomPagerRow.FindControl("gvpanel");

    DropDownList dd = (DropDownList)p.FindControl("ddpage");
    for (int i = 0; i < rcount; i++)
    {
        ListItem li = new ListItem();
        li.Text = (i + 1).ToString();
        li.Value = (i + 1).ToString();
        dd.Items.Add(li);
    }
    Label lbltot = (Label)p.FindControl("lbltot");
    lbltot.Text = GridView1.PageCount.ToString();
    dd.SelectedIndex = GridView1.PageIndex;
    LinkButton lbp10 = (LinkButton)p.FindControl("lbp10");
    lbp10.Enabled = false;
    lbp10.CssClass = "smalllinkbuttonfd";
    LinkButton lbp = (LinkButton)p.FindControl("lbp");
    lbp.Enabled = false;
    lbp.CssClass = "smalllinkbuttonfd";
    LinkButton lbn10 = (LinkButton)p.FindControl("lbn10");
    lbn10.Enabled = false;
    LinkButton lbn = (LinkButton)p.FindControl("lbn");
    lbn.CssClass = "smalllinkbuttonfd";
    lbn.Enabled = false;
    lbn10.CssClass = "smalllinkbuttonfd";
    int cpage = GridView1.PageIndex + 1;
    int totpage = GridView1.PageCount;
    if (cpage > 10)
    {
        lbp10.Enabled = true;
        lbp10.CssClass = "smalllinkbuttonf";
    }
    if (cpage > 1)
    {
        lbp.Enabled = true;
        lbp.CssClass = "smalllinkbuttonf";
    }
    if (cpage < totpage)
    {
        lbn.Enabled = true;
        lbn.CssClass = "smalllinkbuttonf";
    }
    if (cpage + 10 < totpage)
    {
        lbn10.Enabled = true;
        lbn10.CssClass = "smalllinkbuttonf";
    }
    for (int i = 1; i < 11; i++)
    {
        LinkButton lb = (LinkButton)p.FindControl("lb" + i.ToString());
        lb.Enabled = false;
        lb.CssClass = "smalllinkbuttonfd";
    }
    int tstart = cpage / 10;
    int lcount = tstart + 10;
    //int scount = tstart - 10;
    int cnt = 1;
    for (int i = (tstart * 10); i <= ((tstart * 10) + 10); i++)
    {
        if (cnt > 10)
        {
            return;
        } if ((i + 1) > totpage)
        {
            LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
            lb.Enabled = false;
            lb.Text = (i + 1).ToString();
            lb.CssClass = "smalllinkbuttonfd";
            cnt++;
        }
        else
        {
            if ((i + 1) == cpage)
            {
                LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
                lb.Enabled = false;
                lb.Text = (i + 1).ToString();
                lb.CssClass = "smalllinkbuttonfd";
                cnt++;
            }
            else
            {
                LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
                lb.Enabled = true;
                lb.Text = (i + 1).ToString();
                lb.CssClass = "smalllinkbuttonf";
                cnt++;
            }
        }
    }

}

Onlink 按钮现在您可以添加 onclientclick

于 2013-01-04T10:19:02.843 回答
0

这个链接有一个正确的答案与这个答案相结合。

请务必<asp:ScriptManager runat="server" />在您的文档中添加标签。在页眉部分添加 javascript。

function pageLoad(sender, args) {
          //Your jquery code
          }

优秀的参考可以在$(document).ready() 和 pageLoad() 中找到不一样的!

干杯!

于 2015-07-27T15:59:48.757 回答
0

添加到 GridView RowDataBound

If e.Row.RowType = DataControlRowType.Pager Then
  e.Row.Attributes.Add("onclick", "js_function()")
End If
于 2016-10-18T12:52:46.560 回答