?
Solved

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

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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

800 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