Gridview tab/left arrow/right arrow key strokes

Posted on 2007-10-15
Medium Priority
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
  • 3
  • 2
LVL 26

Expert Comment

ID: 20083139
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

ID: 20087651
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

ID: 20087809
>>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

ID: 20088035
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

Rejojohny earned 1500 total points
ID: 20088149
yes ..

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

615 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