Hi in my project page I gave managed to make a gridview editable but
when I changed the cell values and press save button,
at server side code I am getting all the cell values empty? Why?
How to access it?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                        CellPadding="3" DataKeyNames="quotationid" DataSourceID="PubsDataSource">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <Columns>
                        <asp:BoundField DataField="quotationid" HeaderText="quotationid" InsertVisible="False" ReadOnly="True"
                        SortExpression="quotationid" />
                        <asp:TemplateField HeaderText="project_number" SortExpression="project_number">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("narration") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("quotationid") %>' />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="description" SortExpression="description">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("kindattention") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="manager" SortExpression="manager">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("enquiryno") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                </asp:GridView>

            <asp:SqlDataSource ID="PubsDataSource" runat="server" 
                SelectCommand="SELECT * FROM [quotation]"
                UpdateCommand="UPDATE [quotation] set Narration='Changed Narration' where quotationid = @quotationid"
                ConnectionString="<%$ ConnectionStrings:Pubs %>"  />

Or my whole approach is wrong?

I thing you missed "DataKeyField="quotationid" in grdidview

Hi in my project page I gave managed to make a gridview editable but
when I changed the cell values and press save button,
at server side code I am getting all the cell values empty? Why?
How to access it?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                        CellPadding="3" DataKeyNames="quotationid" DataSourceID="PubsDataSource">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <Columns>
                        <asp:BoundField DataField="quotationid" HeaderText="quotationid" InsertVisible="False" ReadOnly="True"
                        SortExpression="quotationid" />
                        <asp:TemplateField HeaderText="project_number" SortExpression="project_number">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("narration") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("quotationid") %>' />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="description" SortExpression="description">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("kindattention") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="manager" SortExpression="manager">
                        <ItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("enquiryno") %>'
                        OnTextChanged="TextBox_TextChanged" BorderStyle="None"></asp:TextBox>
                        </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                </asp:GridView>

            <asp:SqlDataSource ID="PubsDataSource" runat="server" 
                SelectCommand="SELECT * FROM [quotation]"
                UpdateCommand="UPDATE [quotation] set Narration='Changed Narration' where quotationid = @quotationid"
                ConnectionString="<%$ ConnectionStrings:Pubs %>"  />

Or my whole approach is wrong?

I got it, how to access cell value.

string s = ((TextBox)GridView1.Rows[4].Cells[3].Controls[1]).Text;

Now I want to detect that which cell(RowNo-ColumnNo) has been changed
so that I can update database correspondingly.
In my server side code I have textchanged event of TextBox included in Grid,
which occurs that no times equal to no cell text changed. And that all events
occurs before save button click event.

Hi you have to include datakeyname="your primary value in the gridview" then only you can find correct index of the row to update..For more Check out this link
[removed]

Hi you have to include datakeyname="your primary value in the gridview" then only you can find correct index of the row to update..For more Check out this link
Grid view

I have included datakeyname and able to access cell values.

I just want to figure out row-column index that value has been changed.
I have textchanged event(server side), if 3 cells have been changed then it occurs 3 times and then after save button click event occurs. Now in that event I am not able to figure out that for which gridrowcell the event occured.

protected void TextBox_TextChanged(object sender,EventArgs e)
    {
          // For which cell containing Textbox I have come here?
    }

I have included datakeyname and able to access cell values.

I just want to figure out row-column index that value has been changed.
I have textchanged event(server side), if 3 cells have been changed then it occurs 3 times and then after save button click event occurs. Now in that event I am not able to figure out that for which gridrowcell the event occured.

protected void TextBox_TextChanged(object sender,EventArgs e)
    {
          // For which cell containing Textbox I have come here?
    }
protected void TextBox_TextChanged(object sender,EventArgs e)
    {
        GridViewRow row = (GridViewRow) ((Control)sender).NamingContainer ;

        ((CheckBox)GridView1.Rows[row.RowIndex].Cells[4].Controls[1]).Checked = true;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.