473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ASP to ASP.Net (Datagrid Question)

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



Nov 18 '05 #1
3 1733
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" <dc*******@email.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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




Nov 18 '05 #2
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 tomeet requirements:
1. If no records found, display: "No Records" instead of displaying no rowsat all
2. On Click on any rows, redirect to specific aspx page
3. Each time OnMouseOver and OnMouseOut, the color of the row will bechanged
4. In footer, on the left side there's indicator on the total record, whileon 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



.

Nov 18 '05 #3
DC
Thanks Hermit for the tips and Mahesh for the article. :-)
"DC" <dc*******@email.com> wrote in message
news:#h*************@TK2MSFTNGP09.phx.gbl...
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




Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
0
by: Randy | last post by:
Hello, I have two questions... I have a datagrid. I'm capturing the cell via HitTestInfo. The first question is fairly simple. I'm using an example of how to capture the row/column I found on the...
3
by: BBFrost | last post by:
Ok, I know how to count the number of selected datagrid rows using the code below. What has me stumped is how to determine when the selected rows within a datagrid have been changed. The...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.