简体   繁体   English

如何在devex AspxGridView中获取未绑定的文本框值

[英]how to get unbound textbox values in devex AspxGridView

I've an AspxGridView in my form. 我的表单中有一个AspxGridView。 When I check it's select check box, I trigger ClientSideEvents event and get selected row values to a listbox: 当我选中它的选择复选框时,我触发ClientSideEvents事件并将选定的行值获取到列表框中:

<dx:ASPxListBox ID="listBox" ClientInstanceName="lb" runat="server"
    ValueType="System.String" Width="961px"></dx:ASPxListBox>
<ClientSideEvents SelectionChanged="grid_SelectionChanged" />

function grid_SelectionChanged(s, e) {
    s.GetSelectedFieldValues('A;B;C;D;E;F;G;H;I', GetSelectedFieldValuesCallback);
}      

function GetSelectedFieldValuesCallback(selectedValues) {
        lb.ClearItems();
        if (selectedValues.length == 0) return;
        l = "";
        for (i = 0; i < selectedValues.length; i++) {
            s = "";
            for (j = 0; j < selectedValues[i].length; j++) {
                s = s + selectedValues[i][j] + " - ";
            }
            l = l + s + "\r\n";
            lb.AddItem(s);
        }
    }

In addition, when I add datatextcolumns for textboxes and update js function like as below, I get null values for textboxes. 此外,当我为文本框添加datatextcolumns并更新如下所示的js函数时,我为文本框获取了空值。

<dx:GridViewDataTextColumn FieldName="textBox1" VisibleIndex="9">
    <Settings AllowHeaderFilter="False"></Settings>
    <DataItemTemplate>
       <dx:ASPxTextBox ID="txtBox1" Width="70" runat="server"></dx:ASPxTextBox>
    </DataItemTemplate>
</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn FieldName="textBox2" VisibleIndex="10">
    <Settings AllowHeaderFilter="False"></Settings>
    <DataItemTemplate>
        <dx:ASPxTextBox ID="txtBox2" Width="70" runat="server"></dx:ASPxTextBox>
    </DataItemTemplate>
</dx:GridViewDataTextColumn>

function grid_SelectionChanged(s, e) {
    s.GetSelectedFieldValues('A;B;C;D;E;F;textBox1;textBox2;G;H;I',
                            GetSelectedFieldValuesCallback); 
}

What can I do to solve this problem ? 我该怎么做才能解决这个问题?

the problem is that your txtBox1 and txtBox2 fields are placed inside DataItemTemplate. 问题是您的txtBox1和txtBox2字段放置在DataItemTemplate中。 When item is placed inside an DataItemTemplate you can't reference it directly by server side ID. 将项目放置在DataItemTemplate内时,不能直接通过服务器端ID引用它。 What you need to do is to assign a unique ClientInstanceName to each ASPxTextBox you want to reference at each row. 您需要做的是为要在每一行中引用的每个ASPxTextBox分配一个唯一的ClientInstanceName。

See how DX support suggests to do that: 查看DX支持人员如何建议这样做:

https://www.devexpress.com/Support/Center/Question/Details/T273445 https://www.devexpress.com/Support/Center/Question/Details/T273445

Basically, the idea is that you need to add the server side OnInit event handler to both textboxes: 基本上,这个想法是您需要将服务器端OnInit事件处理程序添加到两个文本框中:

<dx:ASPxTextBox ID="txtBox1" Width="70" runat="server" OnInit="OnTextBox1Init"/>

<dx:ASPxTextBox ID="txtBox2" Width="70" runat="server" OnInit="OnTextBox2Init"/>

and assign the "row's-visible-index-dependent" ClientInstanceName to each instance of the relevant textbox. 并将“行相关的索引相关” ClientInstanceName分配给相关文本框的每个实例。

protected void OnTextBox1Init(object sender, EventArgs e) {
    ASPxTextBox tb1 = sender as ASPxTextBox;
    GridViewDataItemTemplateContainer container = 
    tb1.NamingContainer as GridViewDataItemTemplateContainer;
    tb1.ClientInstanceName = String.Format("txtBox1_{0}", container.VisibleIndex);
}

Then you will be able to get the textbox value using this row-id-dependent ClientInstanceName by calling GetText() over it: txtBox1_1.GetText() for the first textbox at row #1, and so on. 然后,您将能够通过以下方式使用依赖于行ID的ClientInstanceName来获取文本框值:对第1行的第一个文本框调用GetText():txtBox1_1.GetText(),依此类推。

Hope this explanation is enough for you to solve your task. 希望这种解释足以解决您的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM