Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the need to allow a user to "tab through" making edits on a gridview. There will be one editable column in the row data. The user should be able to hit tab and go to the next row to edit said column.

I have not found any easy method to accomplish this task. I found a way to programmatically put a gridview into edit mode, but in testing the code below it works for only 1 row at a time.

        reviewTransferGV.EditIndex = 0;
        reviewTransferGV.Rows[0].RowState = DataControlRowState.Edit;
        reviewTransferGV.EditIndex = 1;
        reviewTransferGV.Rows[1].RowState = DataControlRowState.Edit;
        reviewTransferGV.DataBind();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
210 views
Welcome To Ask or Share your Answers For Others

1 Answer

I did a workaround by creating a property in the page:

protected bool IsEditMode
{
  get { return this.EditMode; }
  set { this.EditMode = value; }
}

Then in the GridView I have the controls for view and edit mode inside an item template. Setting the visibility based on the property value:

<asp:TemplateField SortExpression="Status" HeaderText="Status">
<ItemTemplate>
    <asp:Label Id="lblStatus" Text='<%# Eval("Status") %>' Visible='<%# !IsEditMode %>' runat="server" />
    <asp:TextBox ID="txtStatus" Text='<%# Eval("Status") %>' Visible='<%# IsEditMode %>' runat="server" />
</ItemTemplate>

This works for editing the whole gridview. You'll probably need to make a few modifications to make it work for individual rows.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...