Solved

request.setAttribute for asp .net

Posted on 2004-08-05
1
1,202 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now