如何通过弹出窗口使用JavaScript将值传递到网格视图中的文本框?

时间:2016-09-07 10:51:09

标签: c# asp.net

如何获取所选的文本框索引?如何访问特定行?

var grid = document.getElementById("<%= GridView1.ClientID%>");  
for (var i = 0; i < grid.rows.length - 1; i++) {  
    var txtAmountReceive = $("input[id*=TextBox2]")
    txtAmountReceive[i].value="hello"
    txtAmountReceive[i].Text = "hello";
    var popup = window.open("Default3.aspx", "Popup", "width=300,height=100");
    document.getElementById('<%= GridView1.ClientID %>').Text = "hello";
        popup.focus();
}  

2 个答案:

答案 0 :(得分:0)

根据我的理解,您的弹出页面和网格视图页面都不同。

如果您想使用javascript将值从一个页面传递到另一个页面,那么您可以使用localStorage

Default3.aspx

localStorage.setItem("KeyForAccess", "YourValue");

Gridview页面

var txtAmountReceive = $("input[id*=TextBox2]")

txtAmountReceive[i].value=localStorage.getItem("KeyForAccess");

txtAmountReceive[i].Text =localStorage.getItem("KeyForAccess");

仅供参考:它需要HTML5

答案 1 :(得分:0)

Ans:如何访问特定行

protected void ShowPolicy_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == ("Proceed"))
            {
                GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
                int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
                txtBoxId.Text = Convert.ToString(ShowPolicy.DataKeys[currentRowIndex].Value);
                txtAnotherBox.Text =  Convert.ToString(row.Cells[1].Text)
                //Similarly you can do for other cells.

            }
        }

File.aspx

 <asp:GridView ID="ShowPolicy" runat="server" HorizontalAlign="Center" 

            onrowcommand="ShowPolicy_RowCommand" DataKeyNames="PolicyNumber">
        <Columns>
            <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="ButtonProceed" runat="server" Text="ProceedToEdit" CommandName="Proceed"  CommandArgument='<%#Eval("PolicyNumber") %>'/>


            </ItemTemplate>

            </asp:TemplateField>
        </Columns>
    </asp:GridView>