Data list binding with some text and validating datalist
<p>I am using this code for datalist validation.</p>

<p>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..</p>

<pre><code>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&lt;int&gt; imgIds = (List&lt;int&gt;)ViewState["imgIds"];

            if (htble != null &amp;&amp; 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);
            }
</code></pre>
