ASP to ASP.Net (Datagrid Question)

D

DC

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
 
H

Hermit Dave

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
 
M

Mahesh ChandraMouli

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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top