Hello. Now I`m making web pages, but have some problems.
I`m using Repeater control, and call data from SQL server
and send them to the label in repeater,
as you can see I`m using ItemDatabound. and it looks work, but the result is different that I thought.
In my database like this
UpdateDate UpdateRW(read/write)Auth UpdateRAuth
2016/05/01 U|John|1565;D|HQ|MP84; D|IT Team|M004;
....
UpdateRWAuth and UpdateRAuth rows has two kinds of data.
U| means employeer, John is name, 1565 is emp number
D| means department, HQ is dept name, M004 is dept code.
so I split that data and print like this
R/W Auth R Auth
UpdateDate UpdateUser | UpdateGroup UpdateUser | UpdateGroup
---------------------------------------------------------------------
2016/05/01 John | HQ | IT Team
how can I build a code?
Please, share your knowledge
What I have tried:
public partial class AuthHistory : LayoutsPageBase
{
string folderId;
protected void Page_Load(object sender, EventArgs e)
{
folderId = "/CE Technology Infra/CE PDK Team";
if (!Page.IsPostBack)
{
GetAuthHistory();
}
}
private void GetAuthHistory()
{
DataTable dtAuthHistory = new DataTable();
try
{
dtAuthHistory = AuthHistoryBiz.GetAuthHistory(folderId);
foreach (DataRow row in dtAuthHistory.Rows)
{
lbl_dept.Text = row["Name"].ToString();
lbl_folder.Text = row["FolderName"].ToString();
}
rptAuthHisotry.DataSource = dtAuthHistory;
rptAuthHisotry.DataBind()
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void rptAuthHisotry_ItemDataBound1(object sender, RepeaterItemEventArgs e)
{
DataTable dtAuthHistory = new DataTable();
dtAuthHistory = AuthHistoryBiz.GetAuthHistory(folderId);
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lbl_rwDept = (Label)e.Item.FindControl("lbl_rwDept");
Label lbl_rwUser = (Label)e.Item.FindControl("lbl_rwUser");
Label lbl_UpdateDate = (Label)e.Item.FindControl("lbl_UpdateDate");
foreach (DataRow row in dtAuthHistory.Rows)
{
lbl_UpdateDate.Text = row["UpdateDate"].ToString();
string RWAuth = row["UpdateRWAuth"].ToString();
if (RWAuth.IndexOf(';') > 0)
{
string[] rwAuthArr = RWAuth.Split(';');
foreach (string rwAll in rwAuthArr)
{
if (rwAll.StartsWith("D|"))
{
List<string> deptName = new List<string>();
deptName.Add(rwAll);
foreach (string spdept in deptName)
{
string[] splitDeptName = spdept.Split('|');
lbl_rwDept.Text += splitDeptName[1] + "<br />";
}
}
else if (rwAll.StartsWith("U|"))
{
List<string> userName = new List<string>();
userName.Add(rwAll);
foreach (string spuser in userName)
{
string[] splitUserName = spuser.Split('|');
lbl_rwUser.Text += splitUserName[1] + "<br />";
}
}
}
}
else
{
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}