How to set TabIndex to ButtonField in GridView

Last post 10-29-2009 11:34 AM by WombatEd. 3 replies.

Sort Posts:

  • How to set TabIndex to ButtonField in GridView

    05-29-2007, 12:49 AM
    • Member
      104 point Member
    • amolchikurte
    • Member since 05-29-2007, 4:43 AM
    • Pune,India
    • Posts 45

    Hi Friends,

    (I have creted Gridview control on my form with buttonField/ButtonColumn there are number of controls like dropdown on form. But i dont know how to set the tabIndex propely to ButtonField in GridView. I set it on Click event of another control But whenever I navigate through the gridview finally the tab goes to or focuses on address bar. actually it must have to focus on next tabIndex which is DropDown. So please help me out what should i do. Anser me ASAP.)

    i will explain you my problem, actually  suppose i have a dropdown, gridview and button control, dropdown has tabindex=1,as I select dropdown tab successfully goes to gridview control which i want, also it successfully navigates on that gridview, but now actually problem arises, my next tabindex is Button or submit button, as soon as Tab come out of gridview it should focus on button but it directaly goes to address bar which i don't want.
    this is my problem.. i am not getting what to do.
    ...
    thanks again .. please try to answer me..
     

     

    Thanking You 

    Regards

    AMOL CHIKURTE   

     

    don't forget to "MARK AS ANSWER" if answer is desired.

    Thanks And Regards

    __ AMOL

    Without your involvement you can not succeed.
    With your involvement you can not fail.
  • Re: How to set TabIndex to ButtonField in GridView

    05-31-2007, 9:52 PM
    Answer

    Hi amolchikurte,

    Based on your description, I understand that you want to manually control the TabIndex of the Controls:

     1. DropDownList
     2. GridView’s Button Controls (dynamical amount)
     3. Button

    For this issue, we can set the TabIndex property in GridView1_DataBound event handler. For example:

    <%@ Page Language="C#" %>

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

    <script runat="server">
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            int rowCount = GridView1.Rows.Count;
            int i = 0;
            for (i = 0; i < rowCount; i++)
            {
                Button bt = (Button)GridView1.Rows[i].Cells[0].Controls[0];
                bt.TabIndex = (short)(i + 1);
            }
            Button1.TabIndex = (short)(i + 1);
        }

        System.Data.DataTable myTable;
        protected void Page_Load(object sender, EventArgs e)
        {
            myTable = new System.Data.DataTable();
            myTable.Columns.Add("ID", typeof(int));
            myTable.Columns.Add("Name", typeof(String));
            myTable.Rows.Add(1,"aaa");
            myTable.Rows.Add(2, "bbb");
            myTable.Rows.Add(3, "ccc");
            GridView1.DataSource = myTable;
            GridView1.DataBind();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server" Style="position: static" TabIndex="1">
                <asp:ListItem>aaa</asp:ListItem>
                <asp:ListItem>bbb</asp:ListItem>
            </asp:DropDownList>
            <asp:GridView ID="GridView1" runat="server" Style="position: static" OnDataBound="GridView1_DataBound">
                <Columns>
                    <asp:ButtonField ButtonType="Button" Text="Button" />
                </Columns>
            </asp:GridView>
            <asp:Button ID="Button1" runat="server" Style="position: static" Text="Button" TabIndex="2" /></div>
        </form>
    </body>
    </html>

     

    Sincerely,
    Benson Yu
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
  • Re: How to set TabIndex to ButtonField in GridView

    06-02-2007, 9:48 AM
    • Member
      104 point Member
    • amolchikurte
    • Member since 05-29-2007, 4:43 AM
    • Pune,India
    • Posts 45

    Dear Sir,

    Thanks for your reply ...

    I got the things which you have written

    but about this code which is on databound event


     protected void GridView1_DataBound(object sender, EventArgs e)
        {
            int rowCount = GridView1.Rows.Count;
            int i = 0;
            for (i = 0; i < rowCount; i++)
            {
                Button bt = (Button)GridView1.Rows[i].Cells[0].Controls[0];
                bt.TabIndex = (short)(i + 1);
            }
            Button1.TabIndex = (short)(i + 1);
        }
     

    you have written it in C# actually i'm using VB in code behind file
    so if possible could u explain this in VB.

    (I got that you are setting the tabindex of Button dynamically with the row count of GridView)


    Thanks a lot sir

    with regards

    AMOL

    don't forget to "MARK AS ANSWER" if answer is desired.

    Thanks And Regards

    __ AMOL

    Without your involvement you can not succeed.
    With your involvement you can not fail.
  • Re: How to set TabIndex to ButtonField in GridView

    10-29-2009, 11:34 AM
    • Member
      70 point Member
    • WombatEd
    • Member since 01-26-2007, 12:10 PM
    • Los Angeles, CA
    • Posts 92

    amolchikurte:
    protected void GridView1_DataBound(object sender, EventArgs e)
        {
            int rowCount = GridView1.Rows.Count;
            int i = 0;
            for (i = 0; i < rowCount; i++)
            {
                Button bt = (Button)GridView1.Rows[i].Cells[0].Controls[0];
                bt.TabIndex = (short)(i + 1);
            }
            Button1.TabIndex = (short)(i + 1);
        }

    Not tested, but:

    Dim I as Integer = 0
    For each ThisRow as GridViewRow in GridView1.Rows

    Dim bt as Button = Ctype(ThisRow.FindControl("ButtonName"), Button)
    bt.TabIndex = I
    I = I + 1

    Next
    Button1.TabIndex = I + 1

    Note:  this approach doesn't require revision if you move the button out of column 0.

Page 1 of 1 (4 items)