zoukankan      html  css  js  c++  java
  • Setting Focus to a TextBox in an EditItemTemplate

    <% @Import Namespace="System.Data" %>
    <% @Import Namespace="System.Data.SqlClient" %>
    <script language="vb" runat="server">
      'Create a connection
      Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
      Dim ddlDataSet as DataSet = New DataSet()

      Sub Page_Load(sender as Object, e as EventArgs)
        If Not Page.IsPostBack then
          BindData()
        End If
      End Sub
     

      Sub BindData()
        '2. Create the command object, passing in the SQL string
        Const strSQL as String = "SELECT FAQID, F.Description FROM tblFAQ F WHERE FAQID <= 25"

        'Set the datagrid's datasource to the datareader and databind
        Dim resultsDataSet as New DataSet()
        Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
        myDataAdapter.Fill(resultsDataSet)  

        dgPopularFAQs.DataSource = resultsDataSet
        dgPopularFAQs.DataBind()   
      End Sub

     
      Sub dgPopularFAQs_Edit(sender as Object, e as DataGridCommandEventArgs)
        dgPopularFAQs.EditItemIndex = e.Item.ItemIndex
        BindData()
       
        ' Create a reference to the TextBox
        Dim descTB as TextBox
        descTB = dgPopularFAQs.Items(e.Item.ItemIndex).Cells(2).FindControl("txtDesc")

        'Set the script to focus and select the TextBox
        RegisterStartupScript("focus", "<script language=""JavaScript"">" & vbCrLf & _
             vbTab & "frmEditFAQs." & descTB.ClientID & ".focus();" & _
             vbCrLf & vbTab & "frmEditFAQs." & descTB.ClientID & ".select();" & _
             vbCrLf & "<" & "/script>")
      End Sub
     
     
      Sub dgPopularFAQs_Cancel(sender as Object, e as DataGridCommandEventArgs)
        dgPopularFAQs.EditItemIndex = -1
        BindData()  
      End Sub
     
     
      Sub dgPopularFAQs_Update(sender as Object, e as DataGridCommandEventArgs)
        ' Create a reference to the TextBox
        Dim descTB as TextBox
        descTB = dgPopularFAQs.Items(e.Item.ItemIndex).Cells(2).FindControl("txtDesc")

        'Display what would have happened in the lblResults label
        lblResults.Text = "You opted to update the Description field to: " & descTB.Text   

        dgPopularFAQs.EditItemIndex = -1
        BindData()  
      End Sub
    </script>

    <form runat="server" id="frmEditFAQs">
      <asp:label id="lblResults" Font-Bold="True" runat="server"
      Font-Italic="True" ForeColor="#aa0000" />
      <p>
     
      <asp:datagrid id="dgPopularFAQs" runat="server"
      AutoGenerateColumns="False"
      HeaderStyle-HorizontalAlign="Center"
      HeaderStyle-BackColor="Red"
      HeaderStyle-ForeColor="White"
      HeaderStyle-Font-Bold="True"
      HeaderStyle-Font-Name="Verdana"
      AlternatingItemStyle-BackColor="#dddddd"
      ItemStyle-Font-Name="Verdana"

      DataKeyField="FAQID"

      OnEditCommand="dgPopularFAQs_Edit"
      OnUpdateCommand="dgPopularFAQs_Update"
      OnCancelCommand="dgPopularFAQs_Cancel">

        <Columns>
      <asp:EditCommandColumn EditText="Edit" UpdateText="Update" CancelText="Cancel" />
      <asp:BoundColumn DataField="FAQID" HeaderText="FAQ ID"
           ItemStyle-HorizontalAlign="Center" ReadOnly="True" />
      <asp:TemplateColumn HeaderText="Question">
        <ItemTemplate>
          <%# DataBinder.Eval(Container.DataItem, "Description") %>
        </ItemTemplate>
     
        <EditItemTemplate>
          <asp:TextBox id="txtDesc" runat="server"
                 Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'
                 Width="95%" />
        </EditItemTemplate>
      </asp:TemplateColumn>
        </Columns>
      </asp:datagrid>
    </form>
  • 相关阅读:
    网络测量中基于Sketch方法的简单介绍
    Reading SBAR SDN flow-Based monitoring and Application Recognition
    Reading Meticulous Measurement of Control Packets in SDN
    Reading SketchVisor Robust Network Measurement for Sofeware Packet Processing
    ovs加dpdk在日志中查看更多运行细节的方法
    后缀数组
    (转载)LCA问题的Tarjan算法
    Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
    Vijos 1816统计数字(计数排序)
    卡特兰数
  • 原文地址:https://www.cnblogs.com/hhq80/p/662527.html
Copyright © 2011-2022 走看看