asp.net

blinkivxx

New Member
I should want to show the whole database and allow page when the page loaded. I add the <BR>founction of "find" to the same page. when the "find" was acted, Data was Bound and Showed, but the "Page_load"<BR>will to be executed. so , the Data After "find" and the whole Data are showed on the same page.<BR>how to do it ?????<BR>whether I shall take advantage to custom "<form>" ? how to do it in ASP.NET??? <BR><BR>Thank you very much!<BR> Sincerely !<BR> Haley<BR><BR>program:<BR><BR><%@ Register Tagprefix="UserControl" TagName="head" src=http://aspmessageboard.com/archive/index.php/"head.ascx"%><BR><%@ Register Tagprefix="UserControl" TagName="footer" src="footer.ascx"%><BR><%@ Import Namespace = "System.Data" %><BR><%@ Import Namespace = "System.Data.SQLClient" %><BR><BR><BR><script language="VB" runat="server"><BR><BR>Sub Page_Load(sender As Object, e As EventArgs)<BR> ' Only bind the data on the first visit to the page<BR> If Not Page.IsPostBack<BR> BindSQL()<BR> End If<BR>End Sub<BR><BR>'Create an variable in Global scope<BR>Dim ResultCount as Integer<BR><BR><BR>Sub BindSQL()<BR> Dim MyConnection As SqlConnection<BR> Dim DS as Dataset<BR> Dim MyCommand As SqlDataAdapter<BR> <BR><BR> Dim strConn As String = "user id=sa;password=;database=**;server=**;"<BR> Dim RcdCount As Integer<BR><BR> 'Open up our connection with our connection object<BR> MyConnection = New SQLConnection(strConn)<BR><BR> 'To execute our Sql Statement and provide out active connection<BR> MyCommand = New SqlDataAdapter("SearchGlossary", MyConnection)<BR> MyCommand.SelectCommand.CommandType=CommandType.St oredprocedure<BR> <BR><BR> 'Create instance of dataset object and fill our predetermined datagrid with it and we name it<BR><BR> DS = new Dataset()<BR> MyCommand.Fill(DS, "pubs")<BR><BR> RcdCount = DS.Tables("pubs").Rows.Count.ToString()<BR> Pubs.Pagesize = CInt(ps.SelectedItem.Value)<BR><BR> If Not Page.IsPostback<BR> Pubs.CurrentPageIndex = 0<BR> End if<BR><BR> ResultCount = RcdCount<BR> RecordCount.Text = "<b><font color=red>" & RcdCount & "</font> record found"<BR><BR> 'Now we assign the dataview to the datasource of the datagrid and we send it right on it<BR> Try<BR> Pubs.DataSource = DS<BR> Pubs.Databind()<BR> Catch e As Exception<BR> Pubs.CurrentPageIndex = 0<BR> End Try<BR><BR> If Pubs.CurrentPageIndex <> 0 Then<BR> Call Prev_Buttons()<BR> Firstbutton.Visible = true<BR> Prevbutton.Visible = true<BR> else<BR> Firstbutton.Visible = false<BR> Prevbutton.Visible = false<BR> end if<BR><BR> If Pubs.CurrentPageIndex <> (Pubs.PageCount-1) then<BR> Call Next_Buttons()<BR> NextButton.Visible = true<BR> Lastbutton.Visible = true<BR> else<BR> NextButton.Visible = false<BR> Lastbutton.Visible = False<BR> end if<BR><BR> lblPageCount.Text = "Page " & Pubs.CurrentPageIndex + 1 & " of " & Pubs.PageCount<BR>End Sub<BR><BR><BR><BR>Sub PagerButtonClick(sender As Object, e As EventArgs)<BR> 'used by external paging UI<BR> Dim arg As String = sender.CommandArgument<BR><BR> Select arg<BR> Case "next":<BR> If (Pubs.CurrentPageIndex < (Pubs.PageCount - 1)) Then<BR> Pubs.CurrentPageIndex += 1<BR> End If <BR><BR> Case "prev":<BR> If (Pubs.CurrentPageIndex > 0) Then<BR> Pubs.CurrentPageIndex -= 1<BR> End If<BR><BR> Case "last":<BR> Pubs.CurrentPageIndex = (Pubs.PageCount - 1)<BR><BR> Case Else:<BR> Pubs.CurrentPageIndex = Convert.ToInt32(arg)<BR> End Select<BR><BR> BindSQL()<BR>End Sub<BR><BR><BR><BR>Sub Prev_Buttons()<BR> Dim PrevSet As String<BR><BR> If Pubs.CurrentPageIndex+1 <> 1 and ResultCount <> -1 Then<BR> PrevSet = Pubs.PageSize<BR> PrevButton.Text = ("< Prev " & PrevSet)<BR> <BR> If Pubs.CurrentPageIndex+1 = Pubs.PageCount Then<BR> FirstButton.Text = ("<< 1st Page")<BR> End If<BR> End If<BR>End Sub<BR><BR><BR>Sub Next_Buttons()<BR> Dim NextSet As String<BR><BR> If Pubs.CurrentPageIndex+1 < Pubs.PageCount Then<BR> NextSet = Pubs.PageSize<BR> NextButton.Text = ("Next" & NextSet & " >")<BR> End If<BR><BR> If Pubs.CurrentPageIndex+1 = Pubs.PageCount-1 Then<BR> Dim EndCount As Integer = ResultCount - (Pubs.PageSize * (Pubs.CurrentPageIndex+1))<BR> NextButton.Text = ("Next" & EndCount & " >")<BR> End If<BR>End Sub<BR><BR><BR>Sub Repage(sender As Object, e As EventArgs)<BR> Pubs.CurrentPageIndex = 0<BR> BindSQL()<BR>End Sub<BR><BR>Sub onClick_button(obj as Object,e as EventArgs)<BR> Dim Glossary as String =box1.text<BR> Dim StrConn as String ="user id=sa;password=;DataBase=**;Server=**;"<BR> Dim objDataSet as New DataSet()<BR> Dim objConn As New SqlConnection(StrConn)<BR> Dim StrSql as String ="select * from Glossary where chinese like '%" & Glossary & "%' or English like '%" & Glossary & "%';" <BR> Dim objAdapter as New sqlDataAdapter(StrSql,objConn)<BR> objAdapter.fill(objDataSet,"Glossary")<BR> <BR> Dim Rcd as string <BR> Rcd=objDataSet.Tables("Glossary").Rows.Count.ToString<BR> Dim objDataView As New DataView(objDataSet.Tables("Glossary"))<BR> DataGrid1.DataSource()=objDataView<BR> DataGrid1.DataBind()<BR> label1.text=Rcd &"record found"<BR> If DataGrid1.Items.Count=0 Then<BR> Label1.Text="sorry,Not found"<BR> End If<BR> End Sub<BR><BR></script><BR><LINK href="images/index.css" rel=stylesheet><BR><BODY leftMargin=0 background=images/mybk2.gif topMargin=1><BR><Center><BR> <UserControl:Head id="myhead" runat="server"/><BR> <asp:Label id="lblPageCount" runat="server" /><BR><BR> <asp:label id="RecordCount" runat="server" /><BR><div align="center"><BR><BR> <table width="77%"><BR> <tr align="center"><BR> <td height="21"><BR> <BR><BR><form runat="server"><BR> Find Glossary:<BR><asp:label id="label1" runat="server"/><BR><asp:textbox id="box1" runat="server"/><BR><asp:button id="button1" text="Find" onClick="onClick_button" runat="server"/><BR><asp:DataGrid id="DataGrid1" runat="server"/><BR><BR><ASP:Datagrid id="Pubs" runat="server" <BR> AllowPaging="True" <BR> AllowCustomPaging="False" <BR> AutoGenerateColumns="False"<BR> <BR> HeaderStyle-HorizontalAlign="Center"<BR> PagerStyle-Visible = "False"<BR> HeaderStyle-BackColor="#00CC00"<BR> HeaderStyle-ForeColor="White"<BR> ><BR> <BR> <Columns><BR> <BR> <asp:BoundColumn HeaderText="ID" DataField="ID"<BR> ItemStyle-HorizontalAlign="Center" /><BR> <asp:BoundColumn HeaderText="Chinese" DataField="Chinese"<BR> ItemStyle-HorizontalAlign="Center" /><BR> <BR><BR> <asp:BoundColumn HeaderText="English" DataField="English"<BR> DataFormatString="{0:d}"<BR> ItemStyle-HorizontalAlign="Right" /><BR> <BR> </Columns><BR> <BR> <BR></asp:DataGrid><BR><BR><BR><BR> <asp:linkbutton id="Firstbutton" Text="<<1st Page" CommandArgument="0" runat="server" onClick="PagerButtonClick"/><BR> <asp:linkbutton id="Prevbutton" Text= "" CommandArgument="prev" runat="server" onClick="PagerButtonClick"/><BR> &nbsp;&nbsp;<BR><BR> <asp:linkbutton id="Nextbutton" Text= "" CommandArgument="next" runat="server" onClick="PagerButtonClick"/><BR> <asp:linkbutton id="Lastbutton" Text="Last Page>>" CommandArgument="last" runat="server" onClick="PagerButtonClick"/><BR><BR> <BR><BR><BR> Change Pagesize<BR> <asp:DropDownList id="ps" runat="server"><BR> <asp:ListItem>4</asp:ListItem><BR> <asp:ListItem>5</asp:ListItem><BR> <asp:ListItem>7</asp:ListItem><BR> <asp:ListItem selected>10</asp:ListItem><BR> <asp:ListItem>12</asp:ListItem><BR> <asp:ListItem>15</asp:ListItem><BR> <asp:ListItem>22</asp:ListItem><BR> </asp:DropDownList><BR> <BR> <asp:button text="Change Pagesize" runat="server" OnClick="RePage"/><BR> </form><BR> </Center><BR> </td><BR></tr><BR></table><BR></div><BR> <BR><BR><UserControl:footer id="myfooter" runat="server"/><BR></body><BR></html
 
Back
Top