Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks,

I have to display grid which looks like excel and should perform inline cell editing i have added few lines of code to achieve this.

Please look into below image

Click Here for image
ASP.NET
<asp:GridView ID="gvLabTATList" runat="server" AutoGenerateColumns="False" CssClass="grid-view"
                            DataKeyNames="serviceid"  OnRowDataBound="gvLabTATList_RowDataBound" OnRowCommand="gvLabTATList_RowCommand" BorderColor="#222222" BorderStyle="Solid" BorderWidth="1px"
                            Width="54%"  
                            OnRowUpdating="gvLabTATList_RowUpdating" ShowFooter="True">
                            <Columns>
                             <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False"/>
                                <asp:TemplateField HeaderText="S No">
                                    <ItemTemplate>
                                        <%# Container.DataItemIndex + 1 %>
                                        <asp:HiddenField ID="hdnServiceID" runat="server" Value='<%# Eval("serviceid") %>' />
                                        <asp:HiddenField ID="hdnID" runat="server" Value='<%# Eval("TATId") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Service">
                                    <ItemTemplate>
                                        <asp:Label ID="txtServiceName" runat="server" Text='<%# Eval("servicename") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="NTDay">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtNTDay" runat="server" Text='<%# Eval("NTDay") %>'></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="NTHour">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtNTHour" runat="server" Text='<%# Eval("NTHour") %>'></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="UTHour">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtUTHour" runat="server" Text='<%# Eval("UTHour") %>'></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="UTMinutes">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtUTMinutes" runat="server" Text='<%# Eval("UTMinutes") %>'></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>


it has to trigger


C#
protected void gvLabTATList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
.....}


Thanks in advance..

What I have tried:

<asp:GridView ID="gvLabTATList" runat="server" AutoGenerateColumns="False" CssClass="grid-view"
DataKeyNames="serviceid" OnRowDataBound="gvLabTATList_RowDataBound" OnRowCommand="gvLabTATList_RowCommand" BorderColor="#222222" BorderStyle="Solid" BorderWidth="1px"
Width="54%"
OnRowUpdating="gvLabTATList_RowUpdating" ShowFooter="True">
<columns> <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False"/>
<asp:TemplateField HeaderText="S No">
<itemtemplate>
<%# Container.DataItemIndex + 1 %>
<asp:HiddenField ID="hdnServiceID" runat="server" Value='<%# Eval("serviceid") %>' />
<asp:HiddenField ID="hdnID" runat="server" Value='<%# Eval("TATId") %>' />


<asp:TemplateField HeaderText="Service">
<itemtemplate>
<asp:Label ID="txtServiceName" runat="server" Text='<%# Eval("servicename") %>'>


<asp:TemplateField HeaderText="NTDay">
<itemtemplate>
<asp:TextBox ID="txtNTDay" runat="server" Text='<%# Eval("NTDay") %>'>


<asp:TemplateField HeaderText="NTHour">
<itemtemplate>
<asp:TextBox ID="txtNTHour" runat="server" Text='<%# Eval("NTHour") %>'>


<asp:TemplateField HeaderText="UTHour">
<itemtemplate>
<asp:TextBox ID="txtUTHour" runat="server" Text='<%# Eval("UTHour") %>'>


<asp:TemplateField HeaderText="UTMinutes">
<itemtemplate>
<asp:TextBox ID="txtUTMinutes" runat="server" Text='<%# Eval("UTMinutes") %>'>


Posted
Updated 12-Jul-16 3:51am
v3
Comments
Suvendu Shekhar Giri 12-Jul-16 7:32am    
.. and what is the problem?
[no name] 12-Jul-16 7:37am    
and after entering the data it is not triggering any event
Suvendu Shekhar Giri 12-Jul-16 7:40am    
What trigger it should fire?
Save?
[no name] 12-Jul-16 7:48am    
protected void gvLabTATList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
.....}
Suvendu Shekhar Giri 12-Jul-16 7:52am    
Put a breakpoint in this event and share your findings after debugging.

1 solution

By default, a GridView data representation control will only allow you to edit one row at a time. Also the RowUpdating event will never fire on textchanged of a TextBox. Keep in mind that doing an auto update on textbox changed is quite expensive to do postback on every change you make. Perhaps using AJAX is doable to cater such feature but I believed that would take a lot of work/time for it to make it work.

As an alternative, you could implement a bulk edit or create a custom control extending GridView. Here are some references that you may want to look at:


[Dynamically Adding and Deleting Rows in GridView and Saving All Rows at Once]


[GridView Bulk Editing]
 
Share this answer
 
v2

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