Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    button focus and searching control problem

    hi all,
    hope someone can advice me on wat needs to be done here...

    ok 1st problem

    i hv a button and i want it to be on focus even when the page loads. i hv tried and here is my code :

    btn_Go.Focus()
    maybe i did not put it at the right place.

    2nd problem

    how do i..u knw...search the database and lets say there are no records OR record mismatch, i can display a text saying "database is empty" or "record not found". wat i have here is, i am using a GridView and i have two datasources. there fore, i am controlling them by using the button click protected sub area. here's the code :

    at the GridView :

    Code:
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Lead_ID" DataSourceID="SqlDataSource1"
            ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="true" />
                <asp:BoundField DataField="Lead_ID" HeaderText="Lead_ID" ReadOnly="True" SortExpression="Lead_ID" />
                <asp:BoundField DataField="Lead_Name" HeaderText="Lead_Name" SortExpression="Lead_Name" />
                <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
                <asp:BoundField DataField="Lead_Status" HeaderText="Lead_Status" SortExpression="Lead_Status" />
                <asp:HyperLinkField HeaderText="Edit" Text="Edit" DataNavigateUrlFields="Lead_ID"
                    DataNavigateUrlFormatString="SFA1EditLeadDetails210107.aspx?ID={0}" />
            </Columns>
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    when page loads it uses sqldatasource1

    Code:
      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            GridView1.DataSourceID = "SqlDataSource2"
            GridView1.DataBind()
        End Sub
    if user uses the search function and when he clicks the button, it changes to sqldatasource2 and then binds them. so lets say if the records does not match the search or db is empty, how do i display those text i mentioned earlier??

    help is really much needed...thank you
    Warm Regards,
    Mivec

  • #2
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone??? pls. help...
    Warm Regards,
    Mivec

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Is focus call in the Page_Load event?
    GridView EmptyDataTemplate is used for no records found.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH View Post
    Is focus call in the Page_Load event?
    GridView EmptyDataTemplate is used for no records found.
    yes....the button focus will be called in when the page loads...

    GridView EmptyDataTemplate...where can i get that??
    Warm Regards,
    Mivec

  • #5
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the GridView problem is solved...now just need the button focus on page load...anyone can help/advice??
    Warm Regards,
    Mivec

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Did you check your page (client-side) for javascript errors?
    The focus call is really just injected as javascript client-side, so if there is any error anywhere else, it may not get called.
    Also, check that you aren't accidentally setting focus to another control somehow. Sometimes the properties of a control do interesting things client-side.
    Do a view-source on the generated page and post it here if you need more help.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •