Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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);
        }
      }
   }
Posted
Updated 7-Jun-16 4:29am
v2
Comments
CHill60 7-Jun-16 10:32am    
Are you saying your table only has three columns and you are storing data in a column that is separated by a | or a ;? If so then start again. You need to normalize your database
PraveenDora 7-Jun-16 19:11pm    
Hi it appears ur getting data from database like cache db , or it some sort of OOBD not RDBMS ..

please post .. explain clearly what is outcome ur getting ,and what is ur expected outcome. aslo ur asp page code or working example..

Regards
Praveen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900