GET THE VALUE OF A BOUNDFIELD FROM A DETAILSVIEW

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
C# 
 1395  View(s)
Ratings:
Rate this:

I seem to always have problems with this. I have a button outside of the View that calls a function that needs an OrderNumber. I keep getting an error,

 

ArgumentOutOfRangeException was unhandled by user code

in debug mode, or this one in the browser,

 

Specified argument was out of the range of valid values.

This is how I'm accessing it:

 

string sOrderNumber = (Order_DetailsView.Rows[0].Cells[0].Controls[0] as TextBox).Text;

int orderNumber = Int32.Parse(sOrderNumber);

I've also tried ((TextBox)Order_DetailsView.Rows[0].Cells[0].Controls[0]).Text and every combination of indexes in Rows[i].Cells[i].Controls[i] that I could fathom.

 

Here is the DetailsView:

 

<asp:DetailsView ID="Order_DetailsView" runat="server" AutoGenerateRows="False">

    <Fields>

        <asp:BoundField DataField="OrderNumber" HeaderText="Order #" />

        <asp:BoundField DataField="GST" HeaderText="GST" DataFormatString="{0:c}" />

        <asp:BoundField DataField="Total" HeaderText="Total" DataFormatString="{0:c}" />

    </Fields>

</asp:DetailsView>

Am I just doing this all wrong? I've looked at every example out there I could find, and my code looks legit from what I can tell. I feel like there must be some simple thing I'm overlooking.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: Get the value of a BoundField from a DetailsView

    There is no textbox in your details its a Cell. So u need to change your code.

    string sOrderNumber = Order_DetailsView.Rows[0].Cells[0].Text.ToString();

    int orderNumber = Int32.Parse(sOrderNumber);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!