0

hi everybody i am trying to update db using gridview but all attempts end up with failure i dont get execptions just nothing happens when i push update button

<asp:GridView ID="ResultGridView" runat="server" AutoGenerateColumns="False" ShowFooter="True"
    DataKeyNames="VendorId" 
    AllowPaging="True" 
    CellPadding="3" 
    OnPageIndexChanging="ResultGridView_PageIndexChanging" 
    OnRowDeleting="ResultGridView_RowDeleting" 
    OnRowEditing="ResultGridView_RowEditing" 
        OnRowUpdating="ResultGridView_RowUpdating" 
        OnRowCancelingEdit="ResultGridView_RowCancelingEdit" PageSize="5" 
        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" 
        CellSpacing="2" OnRowCommand="ResultGridView_RowCommand" 
    >
        <Columns>
            <asp:TemplateField HeaderText="FirstName" SortExpression="VendorFName">
                <EditItemTemplate>
                    <asp:TextBox ID="txtFName" Width="100px" runat="server" Text='<%# Bind("VendorFName") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtFName1" runat="server"  Width="100px"></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("VendorFName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="LastName" SortExpression="VendorLName">
                <EditItemTemplate>
                    <asp:TextBox ID="txtLName"  Width="100px" runat="server" Text='<%# Bind("VendorLName") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtLName1" Width="100px" runat="server" ></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("VendorLName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="City" SortExpression="VendorCity">
                <EditItemTemplate>
                    <asp:TextBox ID="txtCity"  Width="100px" runat="server" Text='<%# Bind("VendorCity") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtCity1"  Width="100px" runat="server" ></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("VendorCity") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="State" SortExpression="VendorState">
                <EditItemTemplate>
                    <asp:TextBox ID="txtState" Width="100px" runat="server" Text='<%# Bind("VendorState") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtState1" Width="100px" runat="server" ></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("VendorState") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Country" SortExpression="VendorCountry">
                <EditItemTemplate>
                    <asp:TextBox ID="txtCountry" Width="100px" runat="server" Text='<%# Bind("VendorCountry") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtCountry1" Width="100px" runat="server" ></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("VendorCountry") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="VendorDescription" SortExpression="VendorDescription">
                <EditItemTemplate>
                    <asp:TextBox ID="txtDescription" TextMode="MultiLine" runat="server" Text='<%# Bind("VendorDescription") %>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtDescription1" runat="server" TextMode="MultiLine" ></asp:TextBox> 
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("VendorDescription") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>




            <asp:TemplateField HeaderText="Edit" ShowHeader="False"> 
            <EditItemTemplate> 
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
                &nbsp;<asp:LinkButton ID="LinkButton5" runat="server">LinkButton</asp:LinkButton>
            </EditItemTemplate> 
            <FooterTemplate> 

            </FooterTemplate> 
            <ItemTemplate> 
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
            </ItemTemplate> 
            </asp:TemplateField> 
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True"  ShowHeader="True" /> 
            <asp:CommandField HeaderText="Select" ShowSelectButton="True"  ShowHeader="True" /> 

        </Columns>
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
    </asp:GridView>







  protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {



        TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Txtfirst");
        TextBox txtlname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Txtlast");
        TextBox txtcityname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Txtcity");
        string key = GridView1.DataKeys[e.RowIndex].Values[0].ToString();


      string qry=  "UPDATE Vendor SET VendorFName ='" + txtlname.Text + "',VendorLName ='" + txtlname.Text
            + "',VendorCity ='" + txtcityname.Text + "'   WHERE VendorId='" +
            GridView1 .DataKeys[e.RowIndex].Values[0].ToString() + "'";
      //  cmd = new SqlCommand( "Update Vendor set VendorFName='" + txtlname.Text + "'VendorLName ='" + txtlname.Text + "'VendorCity='" + txtcityname.Text + "'WHERE VendorID='" + key + "'", conn );
        cmd = new SqlCommand(qry,conn );
        conn.Open();
        cmd.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        conn.Close();




    }

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by sufyan2011
0

Please always wrap the code in <CODE></CODE> tags, its very difficut to understand otherwise, since you are new, we don't like to down vote you.

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.