2010-01-22 56 views
1

使用Asp.Net C#VS08。如何在TextBox上設置值

<%@ 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> 

彈出。想後,選擇在彈出網格行,然後點擊OK按鈕,把價值上的TextBox FO父grid.How設置上父格值。

回答

1

我猜你應該使用網格的行命令事件處理程序,如果我得到你的權利:

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] 
相關問題