Solved

Error message when Trying to Propagate Textbox with field from DataList in ASP.NET

Posted on 2008-06-24
5
372 Views
Last Modified: 2013-11-26
I have a textbox on the page called "PayPeriodId".
I want the textbox to propagate from the PayPeriodId field of a DataList.  I am using the Databound action but am getting the error.  Please let me know what I need to change.
THIS IS THE DATABOUND IN THE CS PAGE:
protected void DataList8_DataBound(object sender, EventArgs e)
    {
        PayPeriodId.Text = DataBinder.Eval(DataList8.DataItem, "PayPeriodId").ToString();
 
    }
}
 
THIS IS THE TEXTBOX:
<asp:TextBox ID="PayPeriodId" runat="server"></asp:TextBox>

Open in new window

0
Comment
Question by:misnstt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:rafayali
ID: 21859281
Try changing DataList8.DataItem to DataListItem.DataItem

Is this textbox inside a datalist itemtemplate? If it is you can simply assign the text property like this

<asp:Textbox id="PayPeriodId" runat="server" text='<%#Eval("PayPeriodId")' />

0
 
LVL 33

Expert Comment

by:raterus
ID: 21859443
DataLists have multiple items, so you need to put this code in ItemDataBound.  If you have a header or footer, you'll need to check for that as well, so you don't try to run the code there.
0
 

Author Comment

by:misnstt
ID: 21859581
Good Afternoon,
The textbox is located outside of the template that is what is making this so difficult.  I changed it to the ItemDataBound but am still having a error.  there are no Header or footers.  The error is where it says DataList8.DataItem.   I think the "DataItem" has to change.


    protected void DataList8_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        PayPeriodId.Text = DataBinder.Eval(DataList8.DataItem, "PayPeriodId").ToString();

    }
0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 21859642
Why are you using a DataList then?  Unless there is only one item, even if you got this working, PayPeriodID will always be set to the last item in the list, is this what you want?

Use this code and it should work,

    protected void DataList8_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        PayPeriodId.Text = DataBinder.Eval(e.Item.DataItem, "PayPeriodId").ToString();

    }
0
 

Author Closing Comment

by:misnstt
ID: 31470322
Hello I have been working on this project for a while.  I am almost finished except for one difficult part.  For me it is difficult but wouldnt be for you.  I would like to pay you to show me how to do what I want since you appear very knowledgble. My direct e-mail is cbomik@hotmail.com if your interested.  Thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question