Home > DeveloperSection > Forums > Get the value of a BoundField from a DetailsView
Royce Roy
Royce Roy

Total Post:134

Posted on    December-03-2014 10:12 PM

 ASP.Net C# 

 1 Reply(s)
 831  View(s)
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">


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

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

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



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.

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    December-04-2014 7:29 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick