Click here to Skip to main content
15,896,154 members
Home / Discussions / Web Development
   

Web Development

 
Questionpublish my web project in LAN Pin
kenny923915-Feb-06 22:38
kenny923915-Feb-06 22:38 
AnswerRe: publish my web project in LAN Pin
Curtis Schlak.16-Feb-06 13:12
Curtis Schlak.16-Feb-06 13:12 
QuestionAsynchronous web search Pin
sammyl3315-Feb-06 7:48
sammyl3315-Feb-06 7:48 
AnswerRe: Asynchronous web search Pin
Shog915-Feb-06 8:40
sitebuilderShog915-Feb-06 8:40 
GeneralRe: Asynchronous web search Pin
sammyl3315-Feb-06 12:13
sammyl3315-Feb-06 12:13 
QuestionDetect Windows XP SP2 Pin
Chintoo72315-Feb-06 1:59
Chintoo72315-Feb-06 1:59 
AnswerRe: Detect Windows XP SP2 Pin
DJLarZ16-Feb-06 2:55
DJLarZ16-Feb-06 2:55 
Questionbeginner problem with databinding Pin
Bart Blommerde14-Feb-06 22:30
Bart Blommerde14-Feb-06 22:30 
After a few evenings of doing tutorials and trying things out, I just encountered my first reallife .NET problem. It concerns dynamic databinding of a Repeater control, using C# and Visual Studio 2005.

For the purpose of binding a number of XML datasources (RSS feeds) to multiple Repeater controls, I made my own implementation of the ITemplate interface :

<br />
public class RssTemplate : ITemplate<br />
{<br />
  static int itemcount = 0;<br />
  ListItemType templateType;<br />
  string title;<br />
  <br />
  public RssTemplate(ListItemType type)<br />
  {<br />
    templateType = type;<br />
  }<br />
<br />
  public RssTemplate(ListItemType type, string t)<br />
  {<br />
    templateType = type;<br />
    title = t;<br />
  }<br />
<br />
  private void TemplateControl_DataBinding(object sender, System.EventArgs e)<br />
  {<br />
    Literal lc;<br />
    lc = (Literal)sender;<br />
    RepeaterItem container = (RepeaterItem)lc.NamingContainer;<br />
    lc.Text = "<a href=\""; <br />
    lc.Text += XPathBinder.Eval(container.DataItem, "link").ToString();<br />
    lc.Text += "\">";<br />
    lc.Text += XPathBinder.Eval(container.DataItem, "title").ToString();<br />
    lc.Text += "</a><br />";<br />
  }<br />
<br />
  public void InstantiateIn(System.Web.UI.Control container)<br />
  {<br />
    Literal lc = new Literal();<br />
    switch (templateType)<br />
    {<br />
    case ListItemType.Header:<br />
      lc.Text = "<b>" + title + "</b><br>";<br />
      break;<br />
    case ListItemType.Item:<br />
      lc.DataBinding += new EventHandler(TemplateControl_DataBinding);<br />
      break;<br />
    case ListItemType.Footer:<br />
      lc.Text = "<br />";<br />
      break;<br />
    }<br />
    container.Controls.Add(lc);<br />
    itemcount += 1;<br />
  }<br />
}<br />



Now I want to loop through a collection of XML urls, fetch the content and bind each dataset to a different Repeater control (see code below). The problem is that the Databind() function, which should bind all datasources to their corresponding controls, binds every control to the first Datasource. I end up having multiple copies of the same RSS items on my page.

I'm sure it's something very trivial I'm overlooking here or it might be that my approach is wrong altogether, but if someone could push me in the right direction here, I would be very grateful.

<br />
OleDbDataReader dtr = cmd.ExecuteReader();<br />
WebFetch wf = new WebFetch();<br />
while (dtr.Read())<br />
{<br />
  // Get RSS feed.<br />
  XmlDataSource xmlds = new XmlDataSource();<br />
  xmlds.Data = wf.fetchURL(dtr.GetString(2));<br />
  xmlds.XPath = "rss/channel/item";<br />
  <br />
  // Construct new repeater control. <br />
  Repeater rss_repeater = new Repeater();<br />
  rss_repeater.DataSource = xmlds;<br />
  rss_repeater.HeaderTemplate = new RssTemplate(ListItemType.Header, dtr.GetString(1));<br />
  rss_repeater.FooterTemplate = new RssTemplate(ListItemType.Footer);<br />
  rss_repeater.ItemTemplate = new RssTemplate(ListItemType.Item);<br />
  RssPlaceHolder.Controls.Add(rss_repeater);<br />
}<br />
dtr.Close();<br />
DataBind();<br />


As stated above : why does DataBind() bind all instances of the Repeater class to the same instance of XMLDataSource, where it should bind (in my opinion) to different instances of XMLDataSource?



-- modified at 4:32 Wednesday 15th February, 2006
AnswerRe: beginner problem with databinding Pin
Bart Blommerde15-Feb-06 9:47
Bart Blommerde15-Feb-06 9:47 
GeneralRe: beginner problem with databinding Pin
George L. Jackson15-Feb-06 13:19
George L. Jackson15-Feb-06 13:19 
Questionproblem in Insert Querey on ASP page Pin
Murtuza Husain Miyan Patel14-Feb-06 21:11
professionalMurtuza Husain Miyan Patel14-Feb-06 21:11 
AnswerRe: problem in Insert Querey on ASP page Pin
Guffa14-Feb-06 21:57
Guffa14-Feb-06 21:57 
AnswerRe: problem in Insert Querey on ASP page Pin
George L. Jackson15-Feb-06 13:25
George L. Jackson15-Feb-06 13:25 
QuestionUPnP media server Pin
bijeesh114-Feb-06 19:55
bijeesh114-Feb-06 19:55 
QuestionScripting Languages Pin
JimmyRopes14-Feb-06 10:43
professionalJimmyRopes14-Feb-06 10:43 
AnswerRe: Scripting Languages Pin
Jeremy Thornton14-Feb-06 12:06
Jeremy Thornton14-Feb-06 12:06 
GeneralRe: Scripting Languages Pin
JimmyRopes14-Feb-06 20:44
professionalJimmyRopes14-Feb-06 20:44 
GeneralRe: Scripting Languages Pin
Stephen Hewitt16-Feb-06 18:46
Stephen Hewitt16-Feb-06 18:46 
GeneralRe: Scripting Languages Pin
Jeremy Thornton18-Feb-06 6:14
Jeremy Thornton18-Feb-06 6:14 
Questionto change email_id's Pin
vivek132314-Feb-06 9:09
vivek132314-Feb-06 9:09 
AnswerRe: to change email_id's Pin
JimmyRopes14-Feb-06 20:55
professionalJimmyRopes14-Feb-06 20:55 
QuestionGroup membership / Windows authentication question Pin
dels_cpp14-Feb-06 6:43
dels_cpp14-Feb-06 6:43 
QuestionABOUT WEBSITE Pin
vivek132314-Feb-06 1:57
vivek132314-Feb-06 1:57 
AnswerRe: ABOUT WEBSITE Pin
vivek-g15-Feb-06 0:36
vivek-g15-Feb-06 0:36 
Questionsearching word or text in web page using ASP Pin
vivek-g14-Feb-06 0:32
vivek-g14-Feb-06 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.