Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-24
5
Medium Priority
?
375 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 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