Solved

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

Posted on 2008-06-24
5
371 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to set focus on a dynamic control 18 48
CSS question 16 62
Windows Universal App 22 57
Building an object from several other objects 4 36
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 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