从一个DetailsView获取绑定列的值 [英] Get the value of a BoundField from a DetailsView

查看:817
本文介绍了从一个DetailsView获取绑定列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎总是有这样的问题。我有一个调用需要一个订单编号功能视图之外的按钮。我不断收到一个错误,

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.

这是我如何访问它:

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

我也试过((文本框)Order_DetailsView.Rows [0] .Cells [0] .Controls [0])。文字和指标的每个组合行[I] .Cells [I] .Controls [I] ,我可以捉摸。

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.

下面是在DetailsView:

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>

我是不是做这一切错了吗?我在每个例子看那里我能找到,我的code看起来与我可以告诉合法的。我觉得一定有我俯瞰一些简单的事情。

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.

推荐答案

有在您的详细信息的单元格没有文本框。所以u需要改变你的code。

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

这篇关于从一个DetailsView获取绑定列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆