Solved

request.setAttribute for asp .net

Posted on 2004-08-05
1
1,232 Views
Last Modified: 2008-01-09
is there a version of request.setAttribute in .net I need to pass a dataset from webform1. to a second web form, that can handle paging in a data grid on the 2nd page?
curently we are using session variables,  is there a better way?
0
Comment
Question by:genesisproject
1 Comment
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
ID: 11728240
Yes use the built in paging like so:

<form id="Form1" method="post" runat="server">
                  <P><asp:label id="Label1" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#4980B9">Manage existing jobs</asp:label>
                        <HR width="100%" SIZE="1">
                  <P></P>
                  <P>
                        <TABLE id="Table1" cellSpacing="0" cellPadding="5" width="100%" border="1">
                              <TR>
                                    <TD class="PageHeader" style="HEIGHT: 24px" colSpan="2">
                                          <asp:Label id="Label2" runat="server" Font-Bold="True">Search Jobs</asp:Label></TD>
                              </TR>
                              <TR>
                                    <TD width="58" style="WIDTH: 58px">
                                          <asp:Label id="Label3" runat="server" Font-Bold="True">Query</asp:Label></TD>
                                    <TD width="338">
                                          <asp:textbox id="SearchQuery" runat="server" MaxLength="50" Columns="15" CssClass="ThinInput"
                                                Width="248px"></asp:textbox></TD>
                              </TR>
                              <TR>
                                    <TD width="58" style="WIDTH: 58px">
                                          <asp:Label id="Label4" runat="server" Font-Bold="True">Match</asp:Label></TD>
                                    <TD width="338">
                                          <asp:dropdownlist id="FieldsToMatch" runat="server" Width="168px">
                                                <asp:ListItem Value="JobNumber" Selected="True">Job Number</asp:ListItem>
                                                <asp:ListItem Value="CustomerID">CustomerID</asp:ListItem>
                                                <asp:ListItem Value="Either">Either</asp:ListItem>
                                          </asp:dropdownlist></TD>
                              </TR>
                              <TR>
                                    <TD align="right" colSpan="2"><INPUT id="FullQuery" type="hidden" name="FullQuery" runat="server">
                                          <asp:button id="SearchProducts" runat="server" Width="64px" CssClass="ThinButton" Text="Search"></asp:button></TD>
                              </TR>
                        </TABLE>
                  </P>
                  <P><asp:datagrid id="dg" runat="server" AllowPaging="True" GridLines="Horizontal" CellPadding="5"
                              AutoGenerateColumns="False" BorderColor="DarkGray" HorizontalAlign="Left" AllowSorting="True"
                              Visible="False">
                              <AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
                              <ItemStyle BackColor="WhiteSmoke"></ItemStyle>
                              <HeaderStyle Font-Bold="True"></HeaderStyle>
                              <Columns>
                                    <asp:TemplateColumn Visible="False" HeaderText="JobNumberID">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "JobNumberID") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="JobNumber">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "JobNumber") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="CustomerID">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "CustomerID") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="StartDate">
                                          <HeaderStyle Width="100px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:MM-dd-yy}") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="EndDate">
                                          <HeaderStyle Width="100px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "EndDate", "{0:MM-dd-yy}") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="AssignedStaff">
                                          <HeaderStyle Width="150px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "AssignedStaff") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Description">
                                          <HeaderStyle Width="450px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "Description") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                          <ItemStyle HorizontalAlign="Right"></ItemStyle>
                                          <ItemTemplate>
                                                <asp:LinkButton id="EditItem" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                              </Columns>
                              <PagerStyle PageButtonCount="20" Mode="NumericPages"></PagerStyle>
                        </asp:datagrid></P>
                  <P>&nbsp;</P>
            </form>

Private Sub BindTheData(Optional ByVal Query As String = "")
        Dim cnn As New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("EmeraldConnStr"))
        Dim cmd As New SqlClient.SqlCommand
        Dim da As New SqlClient.SqlDataAdapter(cmd)
        Dim ds As New DataSet
        Dim dt As New DataTable
        If Query = "" Then Query = FullQuery.Value
        If Query = "" Then
            Query = "SELECT * FROM JobNumbers ORDER BY JobNumber DESC"
        End If
        cmd.CommandText = Query
        cmd.Connection = cnn
        cnn.Open()
        da.SelectCommand = cmd
        da.Fill(dt)
        dg.DataSource = dt
        dg.DataKeyField = "JobNumberID"
        dg.DataBind()
        cnn.Close()
        cmd.Dispose()
        cnn.Dispose()
        dg.Visible = True
    End Sub
    Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dg.PageIndexChanged
        dg.CurrentPageIndex = e.NewPageIndex
        Dim Query As String
        Query = "SELECT * FROM JobNumbers WHERE JobNumbers."
        Select Case FieldsToMatch.SelectedValue
            Case "JobNumber"
                Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%'"
            Case "CustomerID"
                Query &= "CustomerID LIKE '%" & SearchQuery.Text & "%'"
            Case "Either"
                Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%' " & _
                "OR JobNumber.CustomerID LIKE '%" & SearchQuery.Text & "%'"
        End Select
        Query &= " ORDER BY JobNumbers.JobNumberID DESC"
        BindTheData(Query)
        FullQuery.Value = Query
    End Sub
    Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
        If e.CommandName = "Edit" Then
            Response.Redirect("EditJob.aspx?jnid=" & CStr(dg.DataKeys(e.Item.ItemIndex)))
        End If
    End Sub
    Private Sub SearchProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchProducts.Click
        Dim Query As String
        Query = "SELECT * FROM JobNumbers WHERE JobNumbers."
        Select Case FieldsToMatch.SelectedValue
            Case "JobNumber"
                Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%'"
            Case "CustomerID"
                Query &= "CustomerID LIKE '%" & SearchQuery.Text & "%'"
            Case "Either"
                Query &= "JobNumber LIKE '%" & SearchQuery.Text & "%' " & _
                "OR JobNumber.CustomerID LIKE '%" & SearchQuery.Text & "%'"
        End Select
        Query &= " ORDER BY JobNumbers.JobNumberID DESC"
        dg.CurrentPageIndex = 0
        BindTheData(Query)
        FullQuery.Value = Query
    End Sub
End Class

If you have any questions just ask

Regards,

Aeros
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question