开发者

Data list binding with some text and validating datalist

开发者 https://www.devze.com 2023-03-03 15:21 出处:网络
I am using this code for datalist validation. I am binding the image in datalist after that i am trying to give the caption to each image suppose there is 3 image is datalist then for the first image

I am using this code for datalist validation.

I am binding the image in datalist after that i am trying to give the caption to each image suppose there is 3 image is datalist then for the first image i am able to give but for the other one i am unable to.. i think there is some error in conditions help me in this. code is following..

if (DataList1.Items.Count == 0)
            {
                msgError.Text = "Please add images and captions for each image";
                msgError.Focus();
            }
        else 
            AddCaption();
            bool IsEmptyCaption = false;
            Hashtable htble = (Hashtable)ViewState["imgIdCapHtbl"];
            List<int> imgIds = (List<int>)ViewState["imgIds"];

            if (htble != null && imgIds != null)
            {
                foreach (int id in imgIds)
                {
                    if (htble[id] == "")
                    {
                        IsEmptyCaption = true;
                        break;
                    }
                    else
                        IsEmptyCaption = false;

                }
            }
            else
                IsEmptyCaption = true;

           if (DataList1.Items.Count == 0)
        开发者_运维问答    {
                msgError.Text = "Please add images";
                msgError.Focus();
            }
            else if (IsEmptyCaption)
            {
                msgError.Text = "Please add captions for each image";
                msgError.Focus();
            }
            else
            {
                Args[0] = "Section1";
                Args[1] = "";
                Args[2] = FindingId.ToString();
                Args[3] = FindingIdIns.ToString();
                AnotherHeading = false;
                //AddCaption();
                objGetBaseCase.UpdateImageCaptions((Hashtable)ViewState["imgIdCapHtbl"]);
                if (AddFindingsViewerDetails != null)
                    AddFindingsViewerDetails(Args, e);
                ClearImages();
                PageContent pg = (PageContent)this.Parent.FindControl("PageContent");
                if (pg != null)
                    pg.LoadWorkflowForCase();
                if (Display != null)
                    Display(null, EventArgs.Empty);
            }


    if (DataList1.Items.Count == 0)
        {
            msgError.Text = "Please add images and captions for each image";
            msgError.Focus();
        }
    else 
        AddCaption();
        bool IsEmptyCaption = false;
        Hashtable htble = (Hashtable)ViewState["imgIdCapHtbl"];
        List<int> imgIds = (List<int>)ViewState["imgIds"];

        if (htble != null && imgIds != null)
        {
            foreach (int id in imgIds)
            {
                if (htble[id] == "" || htble[id] == null) // New code implemented here
                {
                    IsEmptyCaption = true;
                    break;
                }
                else
                    IsEmptyCaption = false;

            }
        }
        else
            IsEmptyCaption = true;

       if (DataList1.Items.Count == 0)
        {
            msgError.Text = "Please add images";
            msgError.Focus();
        }
        else if (IsEmptyCaption)
        {
            msgError.Text = "Please add captions for each image";
            msgError.Focus();
        }
        else
        {
            Args[0] = "Section1";
            Args[1] = "";
            Args[2] = FindingId.ToString();
            Args[3] = FindingIdIns.ToString();
            AnotherHeading = false;
            //AddCaption();
            objGetBaseCase.UpdateImageCaptions((Hashtable)ViewState["imgIdCapHtbl"]);
            if (AddFindingsViewerDetails != null)
                AddFindingsViewerDetails(Args, e);
            ClearImages();
            PageContent pg = (PageContent)this.Parent.FindControl("PageContent");
            if (pg != null)
                pg.LoadWorkflowForCase();
            if (Display != null)
                Display(null, EventArgs.Empty);
        }

Now its working fine...

0

精彩评论

暂无评论...
验证码 换一张
取 消