Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In page load "How to display the all rows of gridview in edit mode.."
Posted
Updated 19-Apr-12 20:10pm
v2

 
Share this answer
 
v2
Comments
Developers Code 20-Apr-12 2:14am    
Not individual row ..i need to display all the rows in edit mode..then only user can update the selected row...
P.Salini 20-Apr-12 2:20am    
see the updated answer
Please have a look:
Edit Delete in GRIDVIEW[^]

[EDIT]
Please refer this link:
GridView All Rows in Edit Mode[^]
Real world gridview bulk editing[^]
 
Share this answer
 
v4
Comments
Developers Code 20-Apr-12 2:16am    
Not individual row ..i need to display all the rows in edit mode..then only user can update the selected row...
Prasad_Kulkarni 20-Apr-12 2:19am    
Please see the updated answer..
sravani.v 9-May-12 0:10am    
My 5!
Prasad_Kulkarni 9-May-12 0:22am    
Thank You Sravani!
 
Share this answer
 
v4
Comments
Developers Code 20-Apr-12 2:14am    
Not individual row ..i need to display all the rows in edit mode..then only user can update the selected row...
sravani.v 20-Apr-12 2:21am    
see last link once
Hi,

One way is to use SqlDataSource as data source of the GridView and set AutoGenerateEditButton to true. And set UpdateCommand attribute of SqlDataSource to your update statement.

GridView will display a column with Edit button that you can use to update its data to the database.
XML
<asp:GridView
    ID="GridView1"
    runat="server"
    AutoGenerateColumns="False"
    DataKeyNames="DepartmentID"
    DataSourceID="SqlDataSource1"
    AutoGenerateEditButton="true">
    <Columns>
        <asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID"
            InsertVisible="False" ReadOnly="True" SortExpression="DepartmentID" />
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    </Columns>
</asp:GridView>

XML
<asp:sqldatasource xmlns:asp="#unknown">
    ID="SqlDataSource1" 
    runat="server" 
    ConnectionString="<%$ ConnectionStrings:pagingConnectionString %>" 
    SelectCommand="SELECT [DepartmentID], [Name] FROM [Departments]"
    UpdateCommand="UPDATE Departments SET Name=@Name WHERE DepartmentID=@DepartmentID">
</asp:sqldatasource>
 
Share this answer
 
XML
<
<asp:gridview id="GridView1" runat="server" onrowdeleting="GridView1_RowDeleting" xmlns:asp="#unknown">
            OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit"
            Style="margin-bottom: 0px" AutoGenerateColumns="False" ForeColor="#CC0099" GridLines="Vertical">
        


<asp:templatefield itemstyle-width=""50px"" headertext=""Edit"><br" mode="hold" />                    <ItemTemplate>
                        <asp:LinkButton ID="lbtnedit" runat="server" ForeColor="#0C4375" Text="Edit" CommandName="Edit"></asp:LinkButton>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="lbtnupdate" runat="server" ForeColor="#0C4375" Text="Update"
                            CommandName="Update"></asp:LinkButton>
                        <asp:LinkButton ID="lbtncancel" runat="server" ForeColor="#0C4375" Text="Cancel"
                            CommandName="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemStyle Width="50px"></ItemStyle>
                </asp:TemplateField></asp:gridview>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900