0

On one web user control

public void displayFindingSection(int sectionsid,string text,string head)
{
   SectionHeading.Text = head;
   DataSet totImgs;
   totImgs = objGetBaseCase.GetFindingsNewerImages(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

2
  • FindingViwerDisplay uc = (FindingViwerDisplay)LoadControl("FindingViwerDisplay.ascx"); Place it before the loop and check Commented Jun 16, 2011 at 6:59
  • i kept that, then only one image is showing not all Commented Jun 16, 2011 at 7:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

I have done the same, i already used the same code, if am using ur code then i am getting only, one image is showing in one user control, while i am having 2, 3 or more image in table and rest is not showing
Then pass the dataset totImgs in the parameter ..add all image souces in dataset in loop then pass it to displayFindingSection ..Might be it happening you are defining datasource each time and binding it which have only 1 image source..Is your control showing the last image you passed through loop???/
yes it is showing last image, can u plz let me syntax how to do.. which u are saying
My displayFindingSection is taking 3 argument (int sectionsid,string text,string head) then how could i use uc.displayFindingSection(dt); it will show error no overload for method takes '1' arguments
u have to change displayFindingSection is taking 3 argument (int sectionsid,string text,string head to one parameter that will take this dt and then u'll loop on dt in displayFindingSection and fill totImgs according to dt data and at the end u'll bind it ..Now i hope you get my point

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.