Click here to Skip to main content
12,881,367 members (27,166 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
I have problem to rebind data after updating pls can u help how to solve?
I have problem to rebind without updating...
.aspx

<asp:TemplateField HeaderText="Vendor Code">
          <itemtemplate>
              <%# Eval("VendorCode")%>
          </itemtemplate>
          <edititemtemplate>
              <asp:DropDownList runat="server" ID="ddlVendorCode" DataTextField="VendorCode" DataValueField="VendorCode" SelectedValue='<%# Bind("VendorCode", "{0}") %>' >
              
          </edititemtemplate>
          <controlstyle width="150px" />
          <itemstyle width="150px" />




.aspx.cs



protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindDataToGrid();
                }
    }
 
void BindDataToGrid()
    {
        Class1 cls = new Class1(Session["sdbpath"].ToString());
        cls.con.Open();
        string qry = "select * from tblPerson";
        DataTable dt = cls.GridDataTable(qry);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
        GridViewRow row = GridView1.Rows[e.RowIndex];
 
        TextBox txtPersonID = (TextBox)row.FindControl("txtPersonID");
 
        DropDownList ddlVendorCode =
        (DropDownList)row.FindControl("ddlVendorCode");
 
        TextBox txtPersonName = (TextBox)row.FindControl("txtPersonName");
        TextBox txtAddress = (TextBox)row.FindControl("txtAddress");
        TextBox txtContact = (TextBox)row.FindControl("txtContact");
        TextBox txtDesignation = (TextBox)row.FindControl("txtDesignation");
        TextBox txtEmail = (TextBox)row.FindControl("txtEmail");
        
        String PersonID = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string VendorCode = ddlVendorCode.SelectedItem.ToString();
        string PersonName = txtPersonName.Text;
        string Address = txtAddress.Text;
        string Contact = txtContact.Text;
        string Designation = txtDesignation.Text;
        string Email = txtEmail.Text;
  
        Class1 cls1 = new Class1(Session["sdbpath"].ToString());//connectio class define
        cls1.con.Open();
        string qry = "update tblPerson set VendorCode = '" + ddlVendorCode.SelectedItem.ToString() +"' ,PersonName = '" + txtPersonName.Text + "' ,Address = '" + txtAddress.Text + "' ,Contact='" + txtContact.Text + "' ,Designation='" + txtDesignation.Text + "' ,Email='" + txtEmail.Text + "' where PersonID = '" + PersonID + "'";
        cls1.SaveEditDeleteData(qry);
 
        string msg = "alert('Person information has been Upated sucessfully ');";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", msg, true);
 
        GridView1.EditIndex = -1;
        BindDataToGrid();
    }
Posted 17-Feb-13 20:41pm
Updated 17-Feb-13 21:11pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

My suggestion you must bind Dropdownlist at RowDataBound event.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

please bind your dropdownlist on rowdatabound event of gridview
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100