0

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?

Edited by Nitin Daphale: n/a

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Nitin Daphale
0

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.

0

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]

Edited by Ezzaral: n/a

0

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?
    }

Edited by Nitin Daphale: n/a

0

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;
    }

Edited by Nitin Daphale: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.