Update in repeater

G

Guest

Hi all,
I've a problem in an update operation in a repeater.
This in my code:

<asp:Repeater ID="rpCosti" EnableViewState="true" runat="server"
OnItemCommand="OnUpdate">

<ItemTemplate>
<tr>
<td><asp:Label ID="lblCitta" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "City") %>' />
</td>
<td><asp:TextBox ID="txtCosto" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Price") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<ul class="bottoni_bot">
<li>
<asp:Button id="btnSalva" CommandName="update" CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"City") %>' CssClass="bottoneNuovaSalva"
Text="SAVE" runat="server" />
</li>
</ul>
</FooterTemplate>
</asp:Repeater>

and in the code-behind

protected void OnUpdate(object source, RepeaterCommandEventArgs e)
{
Repeater r = (Repeater)source;
if (e.CommandName == "update")
{
string city= e.CommandArgument.ToString();
string price= ((TextBox)e.Item.FindControl("txtCosto")).Text;

}
}


but an error occurred:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object

What's wrong on this?
Thanks a lot.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
but an error occurred:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object

What's wrong on this?


One of the used instances is not initialized, which one? well you have to
debug, take a look at the line number and put a breakpoint there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top