gridview数据绑定中的下拉问题 [英] Dropdown issue in gridview databind

查看:62
本文介绍了gridview数据绑定中的下拉问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新后重新绑定数据有问题可以帮忙解决一下吗?

我有问题要重新绑定而不更新...

.aspx



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











.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();
    }

推荐答案

我的建议你必须在RowDataBound事件中绑定Dropdownlist。
My suggestion you must bind Dropdownlist at RowDataBound event.


我认为你的解决方案就在这里 -

http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTemplate-of-GridView-in-ASPNet.aspx [ ^ ]
I think your solution is here-
http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTemplate-of-GridView-in-ASPNet.aspx[^]


请在gridview的rowdatabound事件上绑定你的下拉列表
please bind your dropdownlist on rowdatabound event of gridview


这篇关于gridview数据绑定中的下拉问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆