开发者

web user control adding items problem

On one web user control

public void displayFindingSection(int sectionsid,string text,string head)
{
   SectionHeading.Text = head;
   DataSet totImgs;
   totImgs = objGetBaseCase.G开发者_开发技巧etFindingsNewerImages(sectionsid);
   FindingViewerlist.DataSource = totImgs;
   DataBind();
   SectionText.Text = text;
}

On other web user control

public void DisplayFindingsViewer(CipCaseWorkflowItem2 item)
{
  FindingViewerDisplay.Visible = true;
  ImageAndSimpleViewer.Visible = false;
  objGetBaseCase.GetFindingsImages((Convert.ToInt32(Session["CaseId"])), item.ItemId);
  FindingsViewerNew = objGetBaseCase.GetFindingViewerNewElementDetails(item.ItemId);

  for (int i = 0; i < FindingsViewerNew.Count; i++)
  { 

    FindingViwerDisplay uc =  (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");                 
 FindingPlaceholder.Controls.Add(uc);
  uc.displayFindingSection(Convert.ToInt32(FindingsViewerNew[i].Index), FindingsViewerNew[i].Text, FindingsViewerNew[i].Title);

   }
}

I am adding the all the image in user control and displaying the image, but when i am using the above code, web user control is also adding every time and one image is showing in in control what i want is all images should show in only one user control.. sectionsid is getting the image id from the database. I think prob with for loop but i am unable to solve it.. help me it that


Might be it is happening u have defined it inside the loop

 FindingViwerDisplay uc =  (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");                 
 FindingPlaceholder.Controls.Add(uc);

On Each loop you are adding uc and calling displayFindingSection whcich ofcouse add 1 image than loop go back add a new control again and than add one image it will go on till your loop completion so add control once before loop and call just displayFindingSection in loop..

Do this,

 FindingViwerDisplay uc =  (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx");                 
 FindingPlaceholder.Controls.Add(uc);

//define here a dataTabel with three columns let say u have datatable dt
for (int i = 0; i < FindingsViewerNew.Count; i++)
 { 

 dt.Rows.Add(Convert.ToInt32(FindingsViewerNew[i].Index), FindingsViewerNew[i].Text,   FindingsViewerNew[i].Title);


 }
  uc.displayFindingSection(dt);

Then work out on that dt in displayFindingSection

Sorry if i am wrong...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜