Gridview tab/left arrow/right arrow key strokes

Posted on 2007-10-15
Last Modified: 2010-08-05
How can tab/left arrow/right arrow key strokes be enforced in a row of texboxes on a gridview?
Question by:ksfok
    LVL 26

    Expert Comment

    tab happens by default .. setting focus when user clicks on left and right arrow needs to be coded using javascript .. but it would not be user friendly .. imagine a user trying to move within a textbox by hitting the right arrow key and suddenly he is moved to the next control .. that would not be helpful ... why would you want this functionality?


    Author Comment

    My gridview is populated with the below:
        private void BindGrid()
            int listMAX = 10;
            List<_MyDataClassObject> items = new List<_MyDataClassObject>(listMAX);
            for (int i = 0; i < listMAX; i++)
                _MyDataClassObject c = new _MyDataClassObject();
                c.SiteCode = (int)Session["SiteCode"];
                c.OfficeNumber = (int)Session["OfficeID"];
                c.Location = (string)Session["Location"];
                c.DM_Validated = false;
                c.ToothNum = "";
                c.Surface = "";
                c.Quad = "";

            GridView1.DataSource = items;

    And here's the gridview layout:
           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="2"
                ForeColor="#333333" GridLines="None" CellSpacing="1" OnRowCreated="GridView_Merge_Header_RowCreated" OnRowEditing="GridView1_RowEditing">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <asp:CommandField ShowEditButton="True" HeaderText="Row" />
                    <asp:TemplateField HeaderText="Chk" HeaderStyle-CssClass="newhdr">
                            <asp:CheckBox ID="chkValidated" runat="server" Checked='<%# Bind("DM_Validated") %>'
                                Width="5px" TabIndex="0" Enabled="false"></asp:CheckBox>

    How can I make the Edit command work?  Right now as I test it with the below event:
       protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
            TextBox txtbox = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[3].FindControl("txtTranDate");
            txtbox.Text = GridView1.Rows[e.NewEditIndex].RowState.ToString();

    txtbox.Text  displays "Normal".
    Please help.

    LVL 26

    Expert Comment

    >>txtbox.Text  displays "Normal".
    Sorry, is it still related to the same question or is this another one because I did not quite understand what you mean here .. I can say you cannot set focus the way you have done it in your code .. you will need to render a javascript to set the focus on the control

    TextBox txtbox = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[3].FindControl("txtTranDate");
    page.registerclientscriptblock(me.gettype(), "setfocus", document.getElementById('" & txtbox.clientid & "').focus();")


    Author Comment

    I have a row of many textboxes and dropdowns to feed with that tabbing mechanism. So I figure if I can make the whole row as being edited then all the tabbing will be taken care of by RowState = Edit. Is that a possible solution? I am fraid that will work only with dataset as datasource and not with my current object list? Thanks.
    LVL 26

    Accepted Solution

    yes ..

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now