ASKER
using (SqlConnection cn = new SqlConnection("MyConnectionString"))
{
SqlCommand cm = new SqlCommand("MyStoredProcedure", cn);
cm.CommandType = CommandType.StoredProcedure;
cn.Open();
using (IDataReader dr = cm.ExecuteReader())
{
myRepeater.DataSource = dr;
myRepeater.DataBind();
}
}
ASKER
public int CountFormsAvailables(RepeaterItem item)
{
IDataRecord record = item.DataItem as IDataRecord;
return (Convert.ToInt32(record["PreId"]) > 0 ? 1 : 0) + (Convert.ToInt32(record["PostId"]) > 0 ? 1 : 0) + (Convert.ToInt32(record["PendId"]) > 0 ? 1 : 0);
}
<asp:PlaceHolder runat="server" ID="PostForm" Visible='<%# Convert.ToInt32(Eval("PostId")) > 0 %>'>
<asp:PlaceHolder runat="server" ID="PendForm" Visible='<%# Convert.ToInt32(Eval("PendId")) > 0 %>'>
SELECT
a.Date,
ISNULL(b.Id2, 0) AS TableBId2
FROM
TableA AS a
LEFT JOIN
TableB AS b
ON b.Id = a.Id
ASKER
ASKER
<%@ Import Namespace="System.Data" %>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
const int ItemsPerPage = 5;
int itemCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dtt = new DataTable();
dtt.Columns.Add("Name", typeof(string));
dtt.Columns.Add("SubmitDate", typeof(DateTime));
dtt.Columns.Add("PreId", typeof(int));
dtt.Columns.Add("PostId", typeof(int));
dtt.Columns.Add("PendId", typeof(int));
dtt.Columns.Add("PreStatus", typeof(int));
dtt.Columns.Add("PostStatus", typeof(int));
dtt.Columns.Add("PendStatus", typeof(int));
dtt.Columns.Add("Description", typeof(string));
// Sample data
for (int i = 1; i < 8; i++)
{
dtt.Rows.Add("Dan Smith" + i, new DateTime(2011, 3, 23), 1, 0, 5, 12, 8, 3, "Business Trip - Japan");
dtt.Rows.Add("Mark Jones" + i, new DateTime(2011, 4, 21), 4676, 8876, 6321, 11, 6, 4, "Vacation - Bahamas");
dtt.Rows.Add("Mike Schmidt" + i, new DateTime(2011, 4, 22), 4766, 8900, 6543, 11, 6, 3, "Business Trip – China");
}
myRepeater.DataSource = dtt.CreateDataReader();
myRepeater.DataBind();
HyperLinkPrevious.NavigateUrl = "RepeaterExample3.aspx?page=" + (CurrentPage - 1);
HyperLinkPrevious.Enabled = CurrentPage > 1;
HyperLinkNext.NavigateUrl = "RepeaterExample3.aspx?page=" + (CurrentPage + 1);
}
}
public int CountFormsAvailables(RepeaterItem item)
{
IDataRecord record = (IDataRecord)item.DataItem;
return (Convert.ToInt32(record["PreId"]) > 0 ? 1 : 0) + (Convert.ToInt32(record["PostId"]) > 0 ? 1 : 0) + (Convert.ToInt32(record["PendId"]) > 0 ? 1 : 0);
}
int currentPage = 0;
public int CurrentPage
{
get
{
if (currentPage > 0)
return currentPage;
int.TryParse(Request.QueryString["page"], out currentPage);
if (currentPage <= 0)
currentPage = 1;
return currentPage;
}
}
public bool DrawItem()
{
itemCount++;
int from = (ItemsPerPage * CurrentPage) - ItemsPerPage + 1;
int to = from + ItemsPerPage - 1;
return itemCount >= from && itemCount <= to;
}
public bool DrawHeaderOnPreForm(IDataRecord record)
{
return Convert.ToInt32(record["PreId"]) > 0;
}
public bool DrawHeaderOnPostForm(IDataRecord record)
{
return Convert.ToInt32(record["PostId"]) > 0 && Convert.ToInt32(record["PreId"]) == 0;
}
public bool DrawHeaderOnPendForm(IDataRecord record)
{
return Convert.ToInt32(record["PendId"]) > 0 && (Convert.ToInt32(record["PreId"]) == 0 && Convert.ToInt32(record["PostId"]) == 0);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table rules="all" style="width: 600px;">
<thead style="font-weight: bold;">
<tr>
<td>
Name & Department
</td>
<td>
Submit Date
</td>
<td>
Form
</td>
<td>
View File Copy
</td>
<td>
Status
</td>
</tr>
</thead>
<tbody>
<asp:Repeater runat="server" ID="myRepeater">
<ItemTemplate>
<asp:PlaceHolder runat="server" Visible='<%# DrawItem() %>'>
<asp:PlaceHolder runat="server" ID="PreForm" Visible='<%# Convert.ToInt32(Eval("PreId")) > 0 %>'>
<tr>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Eval("Name") %>
</td>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Convert.ToDateTime( Eval("SubmitDate")).ToShortDateString() %>
</td>
<td>
<asp:HyperLink NavigateUrl='<%# "PreFormView.aspx?id=" + Eval("PreId") %>' Text="Pre link"
runat="server" />
</td>
<td>
<asp:HyperLink NavigateUrl='<%# "PreFormView2.aspx?id=" + Eval("PreId") %>' ImageUrl="Images/ViewForm.gif"
runat="server" />
</td>
<td>
<asp:Image ImageUrl='<%# "Images/Status/" + Eval("PreStatus") + ".gif" %>' runat="server" />
</td>
</tr>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="PostForm" Visible='<%# Convert.ToInt32(Eval("PostId")) > 0 %>'>
<tr>
<asp:PlaceHolder runat="server" Visible='<%# DrawHeaderOnPostForm((IDataRecord)Container.DataItem) %>'>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Eval("Name") %>
</td>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Convert.ToDateTime( Eval("SubmitDate")).ToShortDateString() %>
</td>
</asp:PlaceHolder>
<td>
<asp:HyperLink NavigateUrl='<%# "PostFormView.aspx?id=" + Eval("PostId") %>' Text="Post link"
runat="server" />
</td>
<td>
<asp:HyperLink NavigateUrl='<%# "PostFormView2.aspx?id=" + Eval("PostId") %>' ImageUrl="Images/ViewForm.gif"
runat="server" />
</td>
<td>
<asp:Image ImageUrl='<%# "Images/Status/" + Eval("PostStatus") + ".gif" %>' runat="server" />
</td>
</tr>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="PendForm" Visible='<%# Convert.ToInt32(Eval("PendId")) > 0 %>'>
<tr>
<asp:PlaceHolder runat="server" Visible='<%# DrawHeaderOnPendForm((IDataRecord)Container.DataItem) %>'>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Eval("Name") %>
</td>
<td rowspan="<%# CountFormsAvailables(Container) %>">
<%# Convert.ToDateTime( Eval("SubmitDate")).ToShortDateString() %>
</td>
</asp:PlaceHolder>
<td>
<asp:HyperLink NavigateUrl='<%# "PendFormView.aspx?id=" + Eval("PendId") %>' Text="Pend link"
runat="server" />
</td>
<td>
<asp:HyperLink NavigateUrl='<%# "PendFormView2.aspx?id=" + Eval("PendId") %>' ImageUrl="Images/ViewForm.gif"
runat="server" />
</td>
<td>
<asp:Image ImageUrl='<%# "Images/Status/" + Eval("PendStatus") + ".gif" %>' runat="server" />
</td>
</tr>
</asp:PlaceHolder>
</asp:PlaceHolder>
</ItemTemplate>
</asp:Repeater>
</tbody>
<tfoot>
<tr style="font-weight: bold;">
<td colspan="5" style="text-align: center;">
<asp:HyperLink ID="HyperLinkPrevious" runat="server">< Previous Page</asp:HyperLink>
<span>|</span>
<asp:HyperLink ID="HyperLinkNext" runat="server">Next Page ></asp:HyperLink>
</td>
</tr>
</tfoot>
</table>
</form>
</body>
</html>
ASKER
<%@ Import Namespace="System.Data" %>
ASKER
<asp:PlaceHolder runat="server" Visible='<%# DrawHeaderOnPostForm((IDataRecord)Container.DataItem) %>'>
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
If you need to do something based on the data first, such such as choose an image to display and then show that image instead, then you've got two options for the GridView:
1. Use a TemplateField - this will let you format a column however you see fit... But you'll have to tell it exactly what you want it to do.
More information: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx
2. Use the GridView's RowDatabound event - this will let you hook into the row after it has received data but before that data is rendered... So you can manipulate what will actually be displayed.
More information: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx