Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP to ASP.Net (Datagrid Question)

Reply
Thread Tools

ASP to ASP.Net (Datagrid Question)

 
 
DC
Guest
Posts: n/a
 
      12-22-2003
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">
<aspataGrid 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>
</aspataGrid>
</form>

....



Thanks in advance for your help.



- DC











 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      12-22-2003
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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">
> <aspataGrid 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>
> </aspataGrid>
> </form>
>
> ...
>
>
>
> Thanks in advance for your help.
>
>
>
> - DC
>
>
>
>
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Mahesh ChandraMouli
Guest
Posts: n/a
 
      12-23-2003
Hi,

Please check URL, it has detailed information
http://www.informit.com/isapi/produc...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">
><aspataGrid 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>
></aspataGrid>
></form>
>
>....
>
>
>
>Thanks in advance for your help.
>
>
>
>- DC
>
>
>
>
>
>
>
>
>
>
>
>.
>

 
Reply With Quote
 
DC
Guest
Posts: n/a
 
      12-23-2003
Thanks Hermit for the tips and Mahesh for the article.
"DC" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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">
> <aspataGrid 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>
> </aspataGrid>
> </form>
>
> ...
>
>
>
> Thanks in advance for your help.
>
>
>
> - DC
>
>
>
>
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
global filter to redirect asp (old asp!) pages on asp.net site Daves ASP .Net 2 05-31-2006 08:33 AM
2.0: asp:Menu, asp:XmlDataSource, asp:PlaceHolder R.A.M. ASP .Net 1 03-29-2006 07:55 AM
[ASP.NET1.1]Should I kill the ASP.NET worker process after recompilingmy ASP.NET webservice? Andrea Raimondi ASP .Net 1 02-06-2006 08:10 AM
ASP.Net cookie -> ASP -> ASP.Net Ben ASP .Net 3 05-28-2004 03:35 PM
LOOP through an ASP form's pages (not ASP.NET - ASP classic) David A. Beck ASP General 10 04-13-2004 05:38 PM



Advertisments