如何在TextBox上设置值

时间:2010-01-22 04:19:10

标签: asp.net

在Asp.Net C#VS08上工作。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">


<link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    <title>Untitled Page</title>
        <link href="StyleSheet.css" rel="stylesheet" type="text/css" />    
    <script type="text/javascript">
    var styleToSelect;
    function onOk() {
    document.getElementById('GridView1').className = styleToSelect;
    }
</script>


<script language="javascript" type="text/javascript">

    function GetRowValue(val) {

   // alert(val);

        document.getElementById("Text1").value = val;

        // hardcoded value used to minimize the code.

        // ControlID can instead be passed as query string to the popup window

        //window.opener.document.getElementById("ctl00_ContentPlaceHolder2_GridView1_txtCOM_NAME").value = val;
        //window.opener.document.getElementById('%=txtCOM_NAME.ClientId%>').value = val;
        //window.opener.document.getElementById("txtParent").value = val;
        //Text1.innerHTML=val;
       // alert(val);


       // window.close();

    }

    function Hello()
    {
     document.getElementById("Text1").value="2";
    }
    </script>





</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

    <asp:LinkButton ID="LinkButton1" runat="server">Please click to select an alternate text style.</asp:LinkButton><br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                    ReadOnly="True" SortExpression="CategoryID" />
                <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:TemplateField>
                    <ItemTemplate>



                        <asp:Button ID="Button2" runat="server" Text="Button" />                       


                        <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
             TargetControlID="Button2"
             PopupControlID="Panel2"  



             BackgroundCssClass="modalBackground"
             DropShadow="true"

             OkControlID="OkButton"

             CancelControlID="CancelButton"

             OnOkScript="onOk()"




             />
                        &nbsp;<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>


                    </ItemTemplate>


                </asp:TemplateField>

            </Columns>
        </asp:GridView>


        <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px" CssClass="modalPopup">
                            &nbsp;<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
                                DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnRowDataBound="GridView2_RowDataBound">
                                <Columns>
                                    <asp:TemplateField HeaderText="ckb">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server"></asp:Label>
                                            <asp:CheckBox ID="CheckBox1" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowSelectButton="True" />
                                    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                                        ReadOnly="True" SortExpression="CategoryID" />
                                    <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                                    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />

                                     <asp:TemplateField>
                                        <AlternatingItemTemplate>
                                            <asp:Button ID="btnSelect" runat="server" Text="Select" />
                                        </AlternatingItemTemplate>
                                        <ItemTemplate>
                                            <asp:Button ID="btnSelect" runat="server" Text="Select" />
                                        </ItemTemplate>
                                    </asp:TemplateField>

                                </Columns>
                            </asp:GridView>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:Button ID="Button3" runat="server" Text="Button" />

                                <div align="center">
      <asp:Button ID="OkButton" runat="server" Text="OK" OnClick="OkButton_Click"  OnClientClick=Hello() />
      <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
                                    <input id="Button4" type="button" value="button" /></div>


            </asp:Panel>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
        </asp:SqlDataSource>
        <br />
        <br />
        <br />
        <br />
        &nbsp;



    </div>

    </form>
</body>
</html>

弹出窗口后。想要在弹出网格上选择一行,然后单击“确定”按钮并将值放在TextBox上作为父网格。如何在父网格上设置值。

1 个答案:

答案 0 :(得分:1)

我猜你应该使用网格的row命令事件处理程序,如果我找到你的话:

OnRowCommand="RowCommand"

然后你可以在网格上添加一个按钮:

<asp:LinkButton ID="LnkButton" runat="server" CommandName="setValue" CommandArgument='<%# Eval("id")%>'>Set value</asp:LinkButton>

以及处理它的方法:

protected void RowCommand(Object sender, GridViewCommandEventArgs e)
  if (e.CommandName=="setValue")
    [do something with e.CommandArgument and close dialog]