Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:06:59+00:00 2026-06-10T08:06:59+00:00

I am tring to edit and update my db using gridview itself.I have nearly

  • 0

I am tring to edit and update my db using gridview itself.I have nearly done everything but my only problem is that i have a dropdown list.I am happy with label for edit and changed it into dropdown list in edit mode.Now i am not able to update the dropdown value alone into my db.I am getting a value called system.web.I am not able to get desired value i am facing difficulty because of literal control.I am a newbie so pls help me out.Thanks in advance mates.
my design:

<asp:GridView runat ="server"  GridLines = "Both" DataKeyNames="book_id"  
 AutoGenerateColumns ="false" CellPadding ="5" CellSpacing ="5" allowpaging="True" allowsorting="True"
 ID="gv_table1" EmptyDataText ="No data exists" OnRowEditing="gv_RowEditing" 
        PageIndex="0" PageSize="10" ToolTip="true"
OnRowCancelingEdit="gv_RowCancelingEdit" OnRowUpdating="gv_RowUpdating" 
        OnRowDeleting="gv_RowDeleting" onpageindexchanging="gv_table1_PageIndexChanging"  
>
<Columns>





<asp:BoundField DataField="book_name"   HeaderText="BookName">
<ControlStyle Width ="60" />
</asp:BoundField>
<asp:BoundField DataField="author_name" HeaderText="Author Name">
<ControlStyle Width ="60" />
</asp:BoundField>
<asp:BoundField DataField="publisher" HeaderText="Publisher">
<ControlStyle Width ="60" />
</asp:BoundField>
<asp:BoundField DataField="year_edition" HeaderText="Year/Edition">
<ControlStyle Width ="60" />
</asp:BoundField>
<asp:BoundField DataField="total_no" HeaderText="Total No">
<ControlStyle Width ="30" />
</asp:BoundField>
<asp:BoundField DataField="available" HeaderText="Available">
<ControlStyle Width ="30" />
</asp:BoundField>
<asp:BoundField DataField="tags" HeaderText="Tags">
<ControlStyle Width ="60" />
</asp:BoundField>
<asp:BoundField DataField="fare" HeaderText="Fare">
<ControlStyle Width ="30" />
</asp:BoundField>
<asp:TemplateField HeaderText="state">
                            <ItemTemplate>
                                <asp:Label ID="drpstatus1" AppendDataBoundItems="True"   Text='<%# Bind("state") %>'   Width ="60" runat="server">

                                </asp:Label >

                            </ItemTemplate>
                            <EditItemTemplate >
                           <asp:DropDownList ID="drpstatus" runat="server"    >
                                <asp:ListItem Text="available" Value="0"></asp:ListItem>
                                <asp:ListItem Text="binding" Value="1"></asp:ListItem>
                                <asp:ListItem Text="lost" Value ="2"></asp:ListItem>
                                <asp:ListItem Text ="notavailable" Value ="3"></asp:ListItem>
                            </asp:DropDownList>


                        </EditItemTemplate>

                            </asp:TemplateField>



 <asp:TemplateField HeaderText ="Options">

                                <itemtemplate >

                                        <asp:linkbutton id="btnEdit" runat="server" commandname="Edit" text="Edit" />

                                        <asp:linkbutton id="btnDelete" runat="server" commandname="Delete" text="Delete" />
                                </itemtemplate>
                                <edititemtemplate>
                                        <asp:linkbutton id="btnUpdate" runat="server" commandname="Update" text="Update" />
                                        <asp:linkbutton id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
                                </edititemtemplate>
                        </asp:templatefield>





</Columns>
</asp:GridView>

my code behind:

 public void setgrid()
    {

            gv_table1.DataSource = con.GetData("select  book_id,book_name,author_name,publisher,year_edition,total_no,state ,available,tags,fare from book_info where status!='deleted'");
            gv_table1.DataBind();
              }
     protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
    {


        gv_table1.EditIndex = e.NewEditIndex;

        this.setgrid();
        if (!IsPostBack)
        {
            Response.Write("not post back"); 
        }

    }

    protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {

        gv_table1.EditIndex = -1;

        this.setgrid();
    }

    public void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {


        string totalno = (gv_table1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text;
        string available = (gv_table1.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
        int total = Convert.ToInt32(totalno);
        int avail = Convert.ToInt32(available);

        if (total < avail)
        {
            Page page = HttpContext.Current.Handler as Page;

            if (page != null)
            {

               string error = "available should not be greater than total no";

                ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + error + "');", true);

            }

        }
        else
        {
            int bookid = Convert.ToInt32(gv_table1.DataKeys[e.RowIndex].Values["book_id"].ToString());
            string bookname = ((TextBox)(gv_table1.Rows[e.RowIndex].Cells[0].Controls[0])).Text;
            string fare = (gv_table1.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox).Text;


            string authorname = ((TextBox)(gv_table1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
            string publisher = ((TextBox)(gv_table1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;
            string yearedition = ((TextBox)(gv_table1.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
            string tags = ((TextBox)(gv_table1.Rows[e.RowIndex].Cells[6].Controls[0])).Text;

            string spacediv3 = Convert.ToString (( LiteralControl)(gv_table1.Rows[e.RowIndex].Cells[8].Controls[0])) ;
            string s = spacediv3 ;
            string status = "active";

            con.parameters("@bookid", DBConnection.Type.eInt, bookid);
            con.parameters("@createduser", DBConnection.Type.eVarchar, "user");
            con.parameters("@status", DBConnection.Type.eVarchar, status);
            con.parameters("@bookname", DBConnection.Type.eVarchar, bookname);
            con.parameters("@authorname", DBConnection.Type.eVarchar, authorname);
            con.parameters("@publisher", DBConnection.Type.eVarchar, publisher);
            con.parameters("@yearedition", DBConnection.Type.eVarchar, yearedition);
            con.parameters("@totalno", DBConnection.Type.eInt, totalno);
            con.parameters("@available", DBConnection.Type.eInt, available);
            con.parameters("@tags", DBConnection.Type.eVarchar, tags);
            con.parameters("@fare", DBConnection.Type.eInt, fare);
            con.parameters("@state", DBConnection.Type.eVarchar, s );
            con.parameters("@createddate", DBConnection.Type.eDateTime, "");
            con.parameters("@modifieduser", DBConnection.Type.eVarchar, "");
            con.parameters("@modifieddate", DBConnection.Type.eDateTime, "");

            con.ExecProcedure("sp_books");
            Response.Redirect("book_add.aspx");
        }
    }

    protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        int bookid = Convert.ToInt32(gv_table1.DataKeys[e.RowIndex].Values["book_id"].ToString());
        string status = "deleted";
        con.parameters("@bookid", DBConnection.Type.eInt, bookid);
        con.parameters("@createduser", DBConnection.Type.eVarchar, "user");
        con.parameters("@status", DBConnection.Type.eVarchar, status);
        con.parameters("@bookname", DBConnection.Type.eVarchar, "");
        con.parameters("@authorname", DBConnection.Type.eVarchar, "");
        con.parameters("@publisher", DBConnection.Type.eVarchar, "");
        con.parameters("@yearedition", DBConnection.Type.eVarchar, "");
        con.parameters("@totalno", DBConnection.Type.eInt, "");
        con.parameters("@available", DBConnection.Type.eInt, "");
        con.parameters("@tags", DBConnection.Type.eVarchar, "");
        con.parameters("@fare", DBConnection.Type.eInt, "");
        con.parameters("@state", DBConnection.Type.eVarchar, "");
        con.parameters("@createddate", DBConnection.Type.eDateTime, "");
        con.parameters("@modifieduser", DBConnection.Type.eVarchar, "");
        con.parameters("@modifieddate", DBConnection.Type.eDateTime, "");

        con.ExecProcedure("sp_books");
        Response.Redirect("book_add.aspx");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:07:01+00:00Added an answer on June 10, 2026 at 8:07 am

    Since your DropDownList is inside a TemplateField you can find the reference via FindControl("ID"):

    public void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridView gv = (GridView)sender;
        GridViewRow row = gv.Rows[e.RowIndex];
        DropDownList ddlStatus = (DropDownList)row.FindControl("drpstatus");
        String selectedStatus = ddlStatus.SelectedValue;
    

    Side-notes:

    1. Use validators instead of postback+alert. On that way you avoid unnecessary postbacks and are able to change the error-layout easily via css.
    2. What is con? I hope it’s no a static connection! https://stackoverflow.com/a/9707060/284240
    3. You’ve used AppendDataBoundItems for a Label. That works only for List-controls like ListBox or DropDownList.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a GridView within an updatepanel. I have gridview generated edit and
I have a Gridview with AutoGenerateColumns=False . I am using a TemplateField to display
I have a product admin web site that has been generated using ASP.NET Dynamic
Hello, I'm developing a project using Ext Js that needs to edit a line
I'm trying to make a very simple asp.net page that binds a GridView using
When trying Edit Table Data in MySQL Workbench 5.2.37, its in read only mode.
I'm trying to edit this submit tag to make it disable itself once I
I'm trying to edit a form with a ImageField and I´m using modelformset_factory in
I am trying to edit grid data and save it to the grid itself
I'm trying to edit the navigation bar but the last li is a little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.