|
Hi , I Hope You fine.
I have some problem with this code for paging in asp.net
this bottom code work correctly without any error but when
I try to place separate code in .VB file then error is begin and occured .I want to separate this code and compiling .vb code using VBC.exe later .(bin/paging.dll)
when do it like me so you retrive only < Previous Page Next Page > in your web browser and you don't retrive list Of data in your web browser.
then i try this job and place <% dopagin() %> in paging.aspx file between ...
then i retrive list of data but when you click next you cannot navigate than more 1 page and when
you click previous page you get error "Index -5 is not non-negative and below total rows count"
how can i correct this code .somebody help me please
thank you very much
-------------Correct pagingDS.aspx Code begin ---------------------
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
Dim pagedData As New pagedDataSource
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
doPaging()
End Sub
Function getTheData() As DataTable
Dim DS As New DataSet()
Dim strConnect As New SQLConnection("server=localhost;uid=sa;pwd=relayer;Database=Northwind")
Dim objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
objSQLAdapter.Fill(DS, "customers")
Return DS.Tables("customers").Copy
End Function
Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 5
Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
btnNext.Visible = ( NOT pagedData.IsLastPage )
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
theDataList.DataSource = pagedData
theDataList.DataBind()
End Sub
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
End Sub
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
End Sub
<title>Paging with ASP.NET - DataSet Example - VB.NET
<asp:label id="pageNumber" runat="server">
<asp:datalist id="theDataList" runat="server">
<itemtemplate>
Company Name: | <%# DataBinder.Eval(Container.DataItem, "companyName") %> | Contact Name: | <%# DataBinder.Eval(Container.DataItem, "contactName") %> | Contact Title: | <%# DataBinder.Eval(Container.DataItem, "contactTitle") %> |
<separatortemplate>
<asp:linkbutton id="btnPrev" text="<" onclick="Prev_Click" runat="server">
<asp:linkbutton id="btnNext" text=">" onclick="Next_Click" runat="server">
-------------------Paging.aspx End Code-----------------------------------------
***********************************************************************
---------------MY .ASPX file begin------------------------
<%@ Page src="paging.vb" language="vb" AutoEventWireup="false" Explicit="True" Inherits="farhad.myfunction2" ContentType="text/html" %>
<title>Paging with ASP.NET - DataSet Example - VB.NET
<asp:label id="pageNumber" runat="server">
<asp:datalist id="theDataList" runat="server">
<itemtemplate>
Company Name: | <%# DataBinder.Eval(Container.DataItem, "companyName") %> | Contact Name: | <%# DataBinder.Eval(Container.DataItem, "contactName") %> | Contact Title: | <%# DataBinder.Eval(Container.DataItem, "contactTitle") %> |
<separatortemplate>
<asp:linkbutton id="btnPrev" text="< Previous Page" onclick="Prev_Click" runat="server">
<asp:linkbutton id="btnNext" text="Next Page > " onclick="Next_Click" runat="server">
------------End My ASPX file ------------------------------
*************************************************
-------MY .VB Code AND CLASS begin--> Paging.vb --------------------
Imports System
Imports System.Data
Imports System.Data.SQLClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Webcontrols
Imports System.Xml
namespace farhad
public class myfunction2 : Inherits Page
public pagedData As New pagedDataSource
public ds As New DataSet()
public strConnect As New SQLConnection("server=localhost;uid=sa;pwd=mysecretpass;Database=northwind")
public objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
public btnPrev AS LinkButton
public btnNext AS LinkButton
public pageNumber AS Label
public theDataList AS DataList
public Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
dopaging()
end sub
public function getTheData() As DataTable
objSQLAdapter.Fill(DS, "customers")
Return DS.Tables("customers").Copy
End function
public Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 5
Try
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
btnNext.Visible = ( NOT pagedData.IsLastPage )
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
theDataList.DataSource = pagedData
theDataList.DataBind()
End Sub
public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
End Sub
public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
End Sub
end class
end namespace
----------------------End My CLASS IN paging.VB FILE----------
|
|
|
|
|
Hello Everyone,
I am trying to use DataBind.Eval(Container.DataItem, "column") in the code behind but when I type in Container.DataItem, it gives me an error. Does anyone know how to use this instead of using it in the aspx page? Thanks
Sincerely,
The Major Rager
|
|
|
|
|
You may only use the DataBind.Eval method in the DataBinding event handler in code-behind. Basically, it is used in the data binding expression right in the web page, I'm curious as to why you need to call it in code-behind.
|
|
|
|
|
hi
this is aavesh..
actually i was trying this code.but its not running a flash file.
i show u how i try to to do it.i hav put the my .swf file in Imagess folder and trying to run it.but it shows me blank box.
<object
classid="clsid27cdb6e-ae6d-11cf-96b8-444553540000"codebase="http: downloa
d.macromedia.com="" pub="" shockwave="" cabs="" flash="" swflash.cab#version="6,0,40,0"WIDTH
="550"" height="400" id="myMovieName" viewastext="">VALUE="~\Imagess\Soft-Orange.swf"> NAME=bgcolor VALUE=#FFFFFF> <embed src="~\Imagess\Soft-Orange.swf" quality="high
bgcolor=#FFFFFF" width="550" height="400" name="myMovieName" align=""
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
one thing which confused me that i don't hav flash software on my PC.
do i need to install it.if it is then how it will run on server.
thanx
|
|
|
|
|
TheMajorRager wrote: I am trying to use DataBind.Eval(Container.DataItem, "column")
well its DataBinder.Eval(<datasource>, <property>)
datasource = is the item being bound to
property = property name
This is done inside of event raised by a control.
If your doing this outside of an event, just grab the data from the data source and dont use the DataBinder
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
I have a panel in which I dynamically add text boxs and drop down list controls Panel1.Controls.Add(myTextBox); When I click a toolbar button the system removes all the controls from the panel. How do I maintain the state of the panel. Thanks.
|
|
|
|
|
The ViewState of the control does not persist its child controls, when you work with dynamic controls, you need to remember to readd the controls on postback, otherwise they get lost.
|
|
|
|
|
Hello,
Is it possible to call a webmethod of a webservice which takes parameters and get a response (string) from Java script?
Please let me know how to achieve if anyone knows it.
Is it possible to do that without using SOAP?
Appreciate your help.
- ashish
|
|
|
|
|
It is possible.
If your web service just takes/returns primitive parameters it is easy. If you get into passing objects around, you'll find it more difficult, requiring rather complex serialization.
This basic idea is available using AJAX. Though it's not limited to calling a webservice, you could just call a web page with a query string.
There are a number of AJAX toolkits out there that should make this reasonably painless for you. See Microsoft ATLAS ATLAS CTP
Or just look for AJAX frameworks. There are several.
Any of them will provide you with numerous examples of the serialization and usage of XmlHttpRequest in javascript.
-- modified at 15:39 Tuesday 1st August, 2006
|
|
|
|
|
Can someone please me out? I got a translatable website where all the translations are currently stored in a DB. I have loaded them into a Dictionaries ect so I need to do is just access them.
What are the implications or advantages of storing it in the cache and application variable respectively? I can't seem to see when is it appropriate to use either?
Thanks in advance
|
|
|
|
|
The Applicaton state (i.e. Application["myVariable"]) and Application Cache (System.Web.HttpContext.Current.Cache.Add(...) in the System.Web.Caching namespace) are similar in purpose. That being that they cache non user specific data in memory on a web server.
The app cache however, offers the following advantages:
1. You can set an expiration policy (sliding, absolute) that dictates when your item will be removed from the memory space. This can be useful with sliding expiration to not hold large items in the cache after they haven't been accessed in say 10 minutes. The absolute is useful if you have mostly static data you want to cache but say it gets updated in its source periodically. You can set the absolute expiration to flush it out of your web app. Coupling that idea with #2:
2. You can set an expiration delegate that will get called when the item is removed from the cache. This can be useful to refresh a stale cache in the case of absolute expiration. Say you have a set of items you offer for sale. You might choose to cache some part of that set. If you realize that your set only changes say in the middle of the night, you might set the absolute expiration accordingly and string an expiration delegate onto it. Then when the item is removed from the cache, you can run some code via the delegate to build a new, updated set and cache that.
So, all in all, app cache lets you be less of a memory hog by controlling when your item is removed. It also allows some interesting ways to keep the cache in sync in certain situations.
|
|
|
|
|
My issue is, I have to allow a user to be able to specify in a text box how many files will be generated.
From that number they enter in the textbox, i generate that number of user controls on the screen for them to fill out.
protected void FileNum_Changed(object sender, EventArgs e)<br />
{<br />
int filecnt = Int32.Parse(txtFileNum.Text.ToString());<br />
ShowFTPControls(filecnt);<br />
<br />
}<br />
private void ShowFTPControls(int Num)<br />
{<br />
ASP.filetransfercontrol_ascx ftc;<br />
<br />
for (int i = 0; i < Num; i++)<br />
{<br />
ftc = new ASP.filetransfercontrol_ascx();<br />
ftc.ID = "ftc" + i;<br />
ftc.EnableViewState = false;<br />
PH.Controls.Add(ftc);<br />
}<br />
}
The problem i'm having is, the user control has autopostback enabled dropdrowlists. When the postback occurs all the dynamic controls are blown away.
Any help would be appreciated. Thanks!
|
|
|
|
|
Have you tried ftc.EnableViewState = true, so that when the page is refreshed the controls will be recreated from the viewstate?
|
|
|
|
|
You then need to remember the number inputted by the user, and on postback you need to recreate the user controls with the ShowFTPControls method. More importantly, if you add the dynamic user controls after the postback data is processed, the event of the dropdownlist will not run properly.
|
|
|
|
|
well hi had a similar problem because i wanted to add dynamic questions on an registration form the solution this.
in your solution is this you must have an hiden field to store the number of control that you have to generate.
the second part is this when o do the postback you have the view state but you dont have the controls so you have to create them in the page init (is where the controls from what i have eard is bound width viewststate.
Note that you have to have exacly the same name. if you want to have events you have to asssign them in the page init to.
if you have master pages (asp.net 2.0) the controls may change name because o the contentplaceholder.
this is the article that i used to resolve the problem
http://www.codeproject.com/aspnet/retainingstate.asp
(note there is an error is not in the page_load but in the page init watch out).
http://www.codeproject.com/useritems/dynamiccontrol.asp
|
|
|
|
|
Hi One & All
This is Naren, I need some small help regarding PageIndex "ToolTip". I got for Header , items but i couldn,t find to get ToolTip for Pageindex .
So plz help me to get the solutions.
I m working in Asp.net with C# web Application.
I wrote some code in datagrid_ItemCreated() ie.,
private void dgEmp_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Pager))
{
e.Item.Cells[0].ToolTip = "Click to get this page"+Currentpageindex;
}
}
This we wrote for PageIndex ToolTip.
"Output" which i m getting is ""Click to get this page 0" for all pageindexes.
So Plz tell me the solutions to do.
Thanking U,
Naren.
please help me
|
|
|
|
|
You need to have a look at the inner of the Cells and get reference to the hyperlink elements which represent the page indexes, you then can set the tooltip for each element.
|
|
|
|
|
Hi,
I need to develop a page with a TreeView control, in which I need to populate data from only a single table.
The requirement is like this: -
1) I have a Date from and Date To option on top of page, where user will specify the date range.
2) There is a Arrange by date and Arrange by process radiobutton, depending on which I need to make the parent node of TreeView and correspondingly arrange data.
The table from where I will fetch data has a structure like this
Column1 + Column 2 = Composite Primary key (neither of which has to be shown as node or child node in the TreeView)
Column3 = Date Column (To be made parent if Arrange by Date radio is selected)
Column4 = Process Column (To be made parent if Arrange by Process radio is selected)
for each date / process child node there will be a batch id node which will become its 3rd level child node.
How do i achieve this in actual? What shld be the query like? what shld the actual logic be like ?
Pls guide me on this
Thanks in advance
|
|
|
|
|
The link in MSDN may get you started, also if you don't know how to write the query you may want to post the question in SQL forum.
TreeView control[^]
|
|
|
|
|
hi, i am using a datalist control which is in another <itemtemplate> of a datalist control.
the inner datalist control has a edit button but i am not able to call the protected override event for the inner datalist control?? how to fire the edit command event of the inner datalist control.
|
|
|
|
|
How do you define the edit button of the inner datalist control? You can also look at the ItemCommand event of the inner datalist control and do a checking on the command name.
|
|
|
|
|
Hi Friend,
I am using Master Page and writing some information on master on dropdownlist_selectedindex
event.
I want to write some values from database to master page on this event and then redirect to an other pages.
Problem is when i redirect it doesnt write information on master page and if i remove redirection line it does.
I am not gettig the sequence of events here.
which event will be best to redirect after writing information to the master page.
any help will be appriciated.
thanks
Naveed Kamboh
|
|
|
|
|
Naveed Kamboh wrote: I want to write some values from database to master page on this event and then redirect to an other pages.
Problem is when i redirect it doesnt write information on master page and if i remove redirection line it does.
Off course, when you redirect the master page reloads. You will need to load the data to the materpage after you redirect. Anytime you redirect to a new page the ViewState of the masterpage is recreated.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks dear but problem is when i redirect to page its goes to that page but does not update informaton on master page
let me xplain my problem again.
M1=Master page
ddl=dropdonwlist on master page
c1=another aspx page which uses master page graphics and info.
variable address;
adress="abc"
at the bottom of master page i wrote like <%=Response.write(address)%>
now i want to redirect my c1 page using ddl index and also change value into address variable which must be updated on to master page.
as ddl's selected index fires at end thats why its not updating information on master page.
any idea to perfrom the task please.
Naveed Kamboh
|
|
|
|
|
use page.master.findcontrol()
You can update any control in the master page at any point. The preRender event is a good place to make sure the update will "stick".
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|