ASP to ASP.Net (Datagrid Question)

Discussion in 'ASP .Net' started by DC, Dec 22, 2003.

  1. DC

    DC Guest

    Dear ASP.Net Experts,

    In ASP, I can write something like this:
    <table>
    <tr>
    <th align=left>ID</th>
    <th align=left>Product Name</th>
    <th align=left>Price</th>
    </tr>
    <%
    ....
    sSQL = "SELECT productID, productName, price ..... "
    .....
    objCmd.CommandText = sSQL
    set rs = objCmd.Execute
    if rs.BOF and rs.EOF then
    %>
    <tr>
    <td align=center>No records</td>
    </tr>
    <%
    else
    do while not rs.EOF
    %>
    <tr onMouseOver='this.style.backgroundColor='yellow'
    onMouseOut='this.style.backgroundColor='white'
    onClick="self.location='view_product.asp?id=<%=rs("productID")%>'">
    <td align=left><%=rs("productID")%></td>
    <td align=left><%=rs("productName")%></td>
    <td align=left><%=FormatCurrency(rs("price"), 2)%></td>
    </tr>
    <%
    rs.MoveNext
    loop
    %>
    <tr>
    <td align=left>Total Record: <%=rs.RecordCount%></td>
    <td>&nbsp;</td>
    <td><!-- #include file=paging.inc --></td>
    </tr>
    <%
    end if
    rs.Close
    set rs = nothing
    %>

    </table>

    How do I implement those in datagrid (ASP.NET), in a sense that it has to
    meet requirements:
    1. If no records found, display: "No Records" instead of displaying no rows
    at all
    2. On Click on any rows, redirect to specific aspx page
    3. Each time OnMouseOver and OnMouseOut, the color of the row will be
    changed
    4. In footer, on the left side there's indicator on the total record, while
    on the right side will display the paging number

    Here is my datagrid snippet:
    ....
    <form name="frmList" runat="server">
    <asp:DataGrid id="dgList" runat="server" Width="100%" CssClass="BodyText"
    AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" PageSize="20" BorderColor="#CC9966"
    BorderStyle="None" BorderWidth="1px"
    BackColor="White" CellPadding="4" HorizontalAlign="Right"
    >

    <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
    BackColor="#FFCC66"></SelectedItemStyle>
    <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" CssClass="headerList"
    BackColor="#990000"></HeaderStyle>
    <FooterStyle HorizontalAlign="Right" ForeColor="#330099"
    CssClass="BodyText" BackColor="#FFFFCC"></FooterStyle>
    <Columns>
    <asp:BoundColumn DataField="productID" SortExpression="productID"
    HeaderText="ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="productName"
    SortExpression="productName" HeaderText="Product Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="price" SortExpression="price"
    HeaderText="Price"></asp:BoundColumn>
    <asp:EditCommandColumn EditText="View" HeaderText="Action"
    ItemStyle-Width="40px"></asp:EditCommandColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" PageButtonCount="5"
    ForeColor="#330099" BackColor="#FFFFCC" CssClass="bodytext"
    Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
    </form>

    ....



    Thanks in advance for your help.



    - DC
     
    DC, Dec 22, 2003
    #1
    1. Advertising

  2. DC

    Hermit Dave Guest

    how bout something like this
    this is from html view of aspx file
    <asp:datagrid id="DataGrid1" runat="server" AllowPaging="True"
    AutoGenerateColumns="False" Width="100%">
    <HeaderStyle Font-Bold="True" BackColor="#E0E0E0"></HeaderStyle>
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <P align="center">
    <asp:HyperLink ImageUrl="../Images/edit.gif" NavigateUrl='<%#
    "CA_EditProduct.aspx?ProductID=" +
    DataBinder.Eval(Container.DataItem,"ProductID") %>' runat="server"
    ID="Hyperlink1"/>
    </P>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <P align="center">
    <asp:HyperLink NavigateUrl='<%#
    "CA_ShowProductColors.aspx?ProductID=" +
    DataBinder.Eval(Container.DataItem,"ProductID") %>' runat="server"
    ID="Hyperlink2">Show
    Colors</asp:HyperLink>
    </P>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="ProductID"
    HeaderText="ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="ProductIdentifier"
    HeaderText="Code"></asp:BoundColumn>
    <asp:BoundColumn DataField="ProductName"
    HeaderText="Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="FoundIn" HeaderText="Product
    In"></asp:BoundColumn>
    <asp:BoundColumn DataField="UnitCost" HeaderText="Unit
    Cost"></asp:BoundColumn>
    <asp:BoundColumn DataField="IsOnSale" HeaderText="On
    Sale"></asp:BoundColumn>
    <asp:BoundColumn DataField="IsActive" HeaderText="Is
    Active"></asp:BoundColumn>
    </Columns>
    <PagerStyle NextPageText="Next" PrevPageText="Prev"></PagerStyle>
    </asp:datagrid>

    from the code behind to actually bind the datagrid (.cs file)

    DataSet myProducts = myProductsDB.GetProducts(getOnlyActiveProducts);
    DataGrid1.DataSource = myProducts;
    DataGrid1.DataBind();

    The myProducDB is instance of a custom class which creates a connection,
    creates a DataAdapter calling a stored proc, fills the DataSet and returns
    it.

    HD

    "DC" <> wrote in message
    news:%...
    > Dear ASP.Net Experts,
    >
    > In ASP, I can write something like this:
    > <table>
    > <tr>
    > <th align=left>ID</th>
    > <th align=left>Product Name</th>
    > <th align=left>Price</th>
    > </tr>
    > <%
    > ....
    > sSQL = "SELECT productID, productName, price ..... "
    > .....
    > objCmd.CommandText = sSQL
    > set rs = objCmd.Execute
    > if rs.BOF and rs.EOF then
    > %>
    > <tr>
    > <td align=center>No records</td>
    > </tr>
    > <%
    > else
    > do while not rs.EOF
    > %>
    > <tr onMouseOver='this.style.backgroundColor='yellow'
    > onMouseOut='this.style.backgroundColor='white'
    >

    onClick="self.location='view_product.asp?id=<%=rs("productID")%>'">
    > <td align=left><%=rs("productID")%></td>
    > <td align=left><%=rs("productName")%></td>
    > <td align=left><%=FormatCurrency(rs("price"), 2)%></td>
    > </tr>
    > <%
    > rs.MoveNext
    > loop
    > %>
    > <tr>
    > <td align=left>Total Record: <%=rs.RecordCount%></td>
    > <td>&nbsp;</td>
    > <td><!-- #include file=paging.inc --></td>
    > </tr>
    > <%
    > end if
    > rs.Close
    > set rs = nothing
    > %>
    >
    > </table>
    >
    > How do I implement those in datagrid (ASP.NET), in a sense that it has to
    > meet requirements:
    > 1. If no records found, display: "No Records" instead of displaying no

    rows
    > at all
    > 2. On Click on any rows, redirect to specific aspx page
    > 3. Each time OnMouseOver and OnMouseOut, the color of the row will be
    > changed
    > 4. In footer, on the left side there's indicator on the total record,

    while
    > on the right side will display the paging number
    >
    > Here is my datagrid snippet:
    > ...
    > <form name="frmList" runat="server">
    > <asp:DataGrid id="dgList" runat="server" Width="100%" CssClass="BodyText"
    > AllowPaging="True" AllowSorting="True"
    > AutoGenerateColumns="False" PageSize="20" BorderColor="#CC9966"
    > BorderStyle="None" BorderWidth="1px"
    > BackColor="White" CellPadding="4" HorizontalAlign="Right"
    > >

    > <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
    > BackColor="#FFCC66"></SelectedItemStyle>
    > <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    > <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"

    CssClass="headerList"
    > BackColor="#990000"></HeaderStyle>
    > <FooterStyle HorizontalAlign="Right" ForeColor="#330099"
    > CssClass="BodyText" BackColor="#FFFFCC"></FooterStyle>
    > <Columns>
    > <asp:BoundColumn DataField="productID" SortExpression="productID"
    > HeaderText="ID"></asp:BoundColumn>
    > <asp:BoundColumn DataField="productName"
    > SortExpression="productName" HeaderText="Product Name"></asp:BoundColumn>
    > <asp:BoundColumn DataField="price" SortExpression="price"
    > HeaderText="Price"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="View" HeaderText="Action"
    > ItemStyle-Width="40px"></asp:EditCommandColumn>
    > </Columns>
    > <PagerStyle HorizontalAlign="Right" PageButtonCount="5"
    > ForeColor="#330099" BackColor="#FFFFCC" CssClass="bodytext"
    > Mode="NumericPages"></PagerStyle>
    > </asp:DataGrid>
    > </form>
    >
    > ...
    >
    >
    >
    > Thanks in advance for your help.
    >
    >
    >
    > - DC
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Hermit Dave, Dec 22, 2003
    #2
    1. Advertising

  3. Hi,

    Please check URL, it has detailed information
    http://www.informit.com/isapi/product_id~{0CB2E00E-6408-
    440C-A853-33D5358A78AF%7D/content/index.asp

    Regards
    Mahesh ChandraMouli
    Microsoft .NET MVP|MCAD(Charter Member)
    >-----Original Message-----
    >Dear ASP.Net Experts,
    >
    >In ASP, I can write something like this:
    ><table>
    > <tr>
    > <th align=left>ID</th>
    > <th align=left>Product Name</th>
    > <th align=left>Price</th>
    > </tr>
    ><%
    > ....
    > sSQL = "SELECT productID, productName,

    price ..... "
    > .....
    > objCmd.CommandText = sSQL
    > set rs = objCmd.Execute
    > if rs.BOF and rs.EOF then
    >%>
    > <tr>
    > <td align=center>No records</td>
    > </tr>
    ><%
    > else
    > do while not rs.EOF
    >%>
    > <tr onMouseOver='this.style.backgroundColor='yellow'
    > onMouseOut='this.style.backgroundColor='white'
    > onClick="self.location='view_product.asp?id=<%=rs

    ("productID")%>'">
    > <td align=left><%=rs("productID")%></td>
    > <td align=left><%=rs("productName")%></td>
    > <td align=left><%=FormatCurrency(rs("price"), 2)%
    ></td>
    > </tr>
    ><%
    > rs.MoveNext
    > loop
    >%>
    ><tr>
    > <td align=left>Total Record: <%=rs.RecordCount%></td>
    > <td> </td>
    > <td><!-- #include file=paging.inc --></td>
    ></tr>
    ><%
    > end if
    > rs.Close
    > set rs = nothing
    >%>
    >
    ></table>
    >
    >How do I implement those in datagrid (ASP.NET), in a

    sense that it has to
    >meet requirements:
    >1. If no records found, display: "No Records" instead of

    displaying no rows
    >at all
    >2. On Click on any rows, redirect to specific aspx page
    >3. Each time OnMouseOver and OnMouseOut, the color of

    the row will be
    >changed
    >4. In footer, on the left side there's indicator on the

    total record, while
    >on the right side will display the paging number
    >
    >Here is my datagrid snippet:
    >....
    ><form name="frmList" runat="server">
    ><asp:DataGrid id="dgList" runat="server" Width="100%"

    CssClass="BodyText"
    >AllowPaging="True" AllowSorting="True"
    > AutoGenerateColumns="False" PageSize="20"

    BorderColor="#CC9966"
    >BorderStyle="None" BorderWidth="1px"
    > BackColor="White" CellPadding="4"

    HorizontalAlign="Right"
    > >

    > <SelectedItemStyle Font-Bold="True"

    ForeColor="#663399"
    >BackColor="#FFCC66"></SelectedItemStyle>
    > <ItemStyle ForeColor="#330099"

    BackColor="White"></ItemStyle>
    > <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"

    CssClass="headerList"
    >BackColor="#990000"></HeaderStyle>
    > <FooterStyle HorizontalAlign="Right"

    ForeColor="#330099"
    >CssClass="BodyText" BackColor="#FFFFCC"></FooterStyle>
    > <Columns>
    > <asp:BoundColumn DataField="productID"

    SortExpression="productID"
    >HeaderText="ID"></asp:BoundColumn>
    > <asp:BoundColumn DataField="productName"
    >SortExpression="productName" HeaderText="Product

    Name"></asp:BoundColumn>
    > <asp:BoundColumn DataField="price"

    SortExpression="price"
    >HeaderText="Price"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="View"

    HeaderText="Action"
    >ItemStyle-Width="40px"></asp:EditCommandColumn>
    > </Columns>
    > <PagerStyle HorizontalAlign="Right"

    PageButtonCount="5"
    >ForeColor="#330099" BackColor="#FFFFCC"

    CssClass="bodytext"
    >Mode="NumericPages"></PagerStyle>
    ></asp:DataGrid>
    ></form>
    >
    >....
    >
    >
    >
    >Thanks in advance for your help.
    >
    >
    >
    >- DC
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >.
    >
     
    Mahesh ChandraMouli, Dec 23, 2003
    #3
  4. DC

    DC Guest

    Thanks Hermit for the tips and Mahesh for the article. :)
    "DC" <> wrote in message
    news:#...
    > Dear ASP.Net Experts,
    >
    > In ASP, I can write something like this:
    > <table>
    > <tr>
    > <th align=left>ID</th>
    > <th align=left>Product Name</th>
    > <th align=left>Price</th>
    > </tr>
    > <%
    > ....
    > sSQL = "SELECT productID, productName, price ..... "
    > .....
    > objCmd.CommandText = sSQL
    > set rs = objCmd.Execute
    > if rs.BOF and rs.EOF then
    > %>
    > <tr>
    > <td align=center>No records</td>
    > </tr>
    > <%
    > else
    > do while not rs.EOF
    > %>
    > <tr onMouseOver='this.style.backgroundColor='yellow'
    > onMouseOut='this.style.backgroundColor='white'
    >

    onClick="self.location='view_product.asp?id=<%=rs("productID")%>'">
    > <td align=left><%=rs("productID")%></td>
    > <td align=left><%=rs("productName")%></td>
    > <td align=left><%=FormatCurrency(rs("price"), 2)%></td>
    > </tr>
    > <%
    > rs.MoveNext
    > loop
    > %>
    > <tr>
    > <td align=left>Total Record: <%=rs.RecordCount%></td>
    > <td>&nbsp;</td>
    > <td><!-- #include file=paging.inc --></td>
    > </tr>
    > <%
    > end if
    > rs.Close
    > set rs = nothing
    > %>
    >
    > </table>
    >
    > How do I implement those in datagrid (ASP.NET), in a sense that it has to
    > meet requirements:
    > 1. If no records found, display: "No Records" instead of displaying no

    rows
    > at all
    > 2. On Click on any rows, redirect to specific aspx page
    > 3. Each time OnMouseOver and OnMouseOut, the color of the row will be
    > changed
    > 4. In footer, on the left side there's indicator on the total record,

    while
    > on the right side will display the paging number
    >
    > Here is my datagrid snippet:
    > ...
    > <form name="frmList" runat="server">
    > <asp:DataGrid id="dgList" runat="server" Width="100%" CssClass="BodyText"
    > AllowPaging="True" AllowSorting="True"
    > AutoGenerateColumns="False" PageSize="20" BorderColor="#CC9966"
    > BorderStyle="None" BorderWidth="1px"
    > BackColor="White" CellPadding="4" HorizontalAlign="Right"
    > >

    > <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
    > BackColor="#FFCC66"></SelectedItemStyle>
    > <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    > <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"

    CssClass="headerList"
    > BackColor="#990000"></HeaderStyle>
    > <FooterStyle HorizontalAlign="Right" ForeColor="#330099"
    > CssClass="BodyText" BackColor="#FFFFCC"></FooterStyle>
    > <Columns>
    > <asp:BoundColumn DataField="productID" SortExpression="productID"
    > HeaderText="ID"></asp:BoundColumn>
    > <asp:BoundColumn DataField="productName"
    > SortExpression="productName" HeaderText="Product Name"></asp:BoundColumn>
    > <asp:BoundColumn DataField="price" SortExpression="price"
    > HeaderText="Price"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="View" HeaderText="Action"
    > ItemStyle-Width="40px"></asp:EditCommandColumn>
    > </Columns>
    > <PagerStyle HorizontalAlign="Right" PageButtonCount="5"
    > ForeColor="#330099" BackColor="#FFFFCC" CssClass="bodytext"
    > Mode="NumericPages"></PagerStyle>
    > </asp:DataGrid>
    > </form>
    >
    > ...
    >
    >
    >
    > Thanks in advance for your help.
    >
    >
    >
    > - DC
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    DC, Dec 23, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bit Byte
    Replies:
    1
    Views:
    854
    Teemu Keiski
    Jan 28, 2007
  2. Andreas Klemt
    Replies:
    0
    Views:
    309
    Andreas Klemt
    Oct 8, 2003
  3. Kostia
    Replies:
    1
    Views:
    267
    Scott Mitchell [MVP]
    Feb 26, 2004
  4. roberto
    Replies:
    1
    Views:
    227
    roberto
    Feb 17, 2005
  5. Phani
    Replies:
    2
    Views:
    126
    Phani
    Apr 25, 2005
Loading...

Share This Page