Link to home
Start Free TrialLog in
Avatar of misnstt
misnstt

asked on

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

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

Avatar of rafayali
rafayali
Flag of Canada image

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")' />

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.
Avatar of misnstt
misnstt

ASKER

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();

    }
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of misnstt

ASKER

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