使用asp.net和gridview控件与寻呼机。
如何向其添加onclientclick,以便只有在onclientclick返回true时才会页面。
这是否可行,因为它可以通过链接完成?
我知道我可以做到这一点
GridView pager page buttons accessibility
myGridView.Attributes.Add(“onClick”,“setOKToClose();”) 但它将它添加到网格中,我希望它只添加到寻呼机
由于
答案 0 :(得分: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%">
</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
答案 1 :(得分:0)
请务必在文档中添加<asp:ScriptManager runat="server" />
标记。在页眉部分添加javascript。
function pageLoad(sender, args) {
//Your jquery code
}
可以在$(document).ready() and pageLoad() are not the same!
中找到优秀的参考资料干杯!
答案 2 :(得分:0)
添加到GridView RowDataBound
If e.Row.RowType = DataControlRowType.Pager Then
e.Row.Attributes.Add("onclick", "js_function()")
End If