Solved

request.setAttribute for asp .net

Posted on 2004-08-05
1
1,218 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Search by two fields at the same time using c# radio button 5 39
Different Delete Messages 7 37
asp.net mvc input file 2 32
Connection String 16 43
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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

16 Experts available now in Live!

Get 1:1 Help Now