H
Hu Dong
HI, I got some difficulties in adding linkbuttons through C# coding. I added
a panel as follows:
<aspanel id="LblNav" Runat="server" Visible="True"
Height="4Px"></aspanel>
then I created a method to generate a few links and inserted into this
panel;
void RenderNav (int CurrentPage, int TotalPage)
LinkButton bn;
for (int i = 1; i <= TotalPage; i++)
{
bn = new LinkButton();
bn.ID = "link" + i.ToString();
bn.Text = i.ToString();
bn.CausesValidation = false;
bn.Command += new CommandEventHandler(NavigationLink_Click);
bn.CommandName = "Numbered";
bn.CommandArgument = i.ToString();
LblNav.Controls.Add(bn);
LblNav.Controls.Add(new LiteralControl(" "));
}
}
the event handler is:
void NavigationLink_Click ( Object sender, CommandEventArgs e ) {
switch ( e.CommandName ) {
case "First": _currentPageNumber = 1; break;
case "Last": _currentPageNumber = Int32.Parse ( TotalPages.Text ); break;
case "Next": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) + 1;
break;
case "Prev": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) - 1;
break;
case "Numbered": _currentPageNumber =
Int32.Parse(e.CommandArgument.ToString()); break; }
BindData();
}
What I expected was, when I clicked the numbered link button, I should jump
to that page. However, it did not work. And the worse thing was, the
linkbutton list had gone when I clicked either of the buttons. There are
four more static linkbuttons in the page, while they all work very
beautiful. I added a break point in the NavigationLink_Click(), but I even
could not get in when I clicked the numbered linkbutton while I got in if I
clicked other four buttons (First, last, prev, and next).
Do you have any idea how to fix this problem? I am struggling with it for
two days...
Thanks!!!
HU
a panel as follows:
<aspanel id="LblNav" Runat="server" Visible="True"
Height="4Px"></aspanel>
then I created a method to generate a few links and inserted into this
panel;
void RenderNav (int CurrentPage, int TotalPage)
LinkButton bn;
for (int i = 1; i <= TotalPage; i++)
{
bn = new LinkButton();
bn.ID = "link" + i.ToString();
bn.Text = i.ToString();
bn.CausesValidation = false;
bn.Command += new CommandEventHandler(NavigationLink_Click);
bn.CommandName = "Numbered";
bn.CommandArgument = i.ToString();
LblNav.Controls.Add(bn);
LblNav.Controls.Add(new LiteralControl(" "));
}
}
the event handler is:
void NavigationLink_Click ( Object sender, CommandEventArgs e ) {
switch ( e.CommandName ) {
case "First": _currentPageNumber = 1; break;
case "Last": _currentPageNumber = Int32.Parse ( TotalPages.Text ); break;
case "Next": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) + 1;
break;
case "Prev": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) - 1;
break;
case "Numbered": _currentPageNumber =
Int32.Parse(e.CommandArgument.ToString()); break; }
BindData();
}
What I expected was, when I clicked the numbered link button, I should jump
to that page. However, it did not work. And the worse thing was, the
linkbutton list had gone when I clicked either of the buttons. There are
four more static linkbuttons in the page, while they all work very
beautiful. I added a break point in the NavigationLink_Click(), but I even
could not get in when I clicked the numbered linkbutton while I got in if I
clicked other four buttons (First, last, prev, and next).
Do you have any idea how to fix this problem? I am struggling with it for
two days...
Thanks!!!
HU