selectedindex和selectedvalue属性是互斥的例外吗?

时间:2014-02-26 12:37:51

标签: c# asp.net gridview

protected void ddlbranchdate_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        DataTable dtgetvalues = new DataTable();
        //objRetailPL.date = Convert.ToDateTime(hdndate.Value);
        objRetailPL.branchdate = ddlbranchdate.SelectedItem.ToString();
        dtgetvalues = objRetailBAL.getbradisdate(objRetailPL);
        foreach(GridViewRow row in gvMeatDispatch.Rows)
        {
            DataTable dtpr = new DataTable();
            DropDownList ddl1 = (DropDownList)row.FindControl("ddlpartyname");
            objRetailPL.branch = dtgetvalues.Rows[0]["branch"].ToString();

            dtpr = objRetailBAL.getbran(objRetailPL);
            ddl1.DataSource = dtpr;
            ddl1.DataTextField = "partyname";
            ddl1.DataValueField = "sno";
            ddl1.DataBind();
            ddl1.Items.Add(new ListItem("--Select--", "0"));
           ddl1.SelectedIndex = ddl1.Items.Count - 1;
        }
    }
 }

为什么我得到这个例外?..

我正在使用动态网格视图并在Button Control的帮助下动态添加行。

外部我宣布另一个下拉列表..如果用户从此下拉列表中选择了一些值 然后自动将值绑定到Dynamic Gridview,Dropdown list values ..

这是我动态控制方法中的Setprevious Data ..我称之为Dropdownlist selectedindexchanged event ..like ..

private void SetPreviousData()
{
    try
    {
        int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentTable"];
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DropDownList ddlpname = (DropDownList)gvMeatDispatch.Rows[rowIndex].Cells[1].FindControl("ddlpartyname");
                    DropDownList ddlbt = (DropDownList)gvMeatDispatch.Rows[rowIndex].Cells[2].FindControl("ddlbirdtype");
                    TextBox txttotwt = (TextBox)gvMeatDispatch.Rows[rowIndex].Cells[3].FindControl("txttotwt");
                    TextBox txttransbirds1 = (TextBox)gvMeatDispatch.Rows[rowIndex].Cells[4].FindControl("txtrateforkg");
                    TextBox txtmort1 = (TextBox)gvMeatDispatch.Rows[rowIndex].Cells[5].FindControl("txtdcno");

                   // Dropdownlist selectedIndex Changed event

                    ddlbranchdate_SelectedIndexChanged(null, null);

                    ddlpname.SelectedValue = dt.Rows[i]["Col1"].ToString();
                    ddlbt.SelectedValue = dt.Rows[i]["Col2"].ToString();
                    txttotwt.Text = dt.Rows[i]["col3"].ToString();
                    txttransbirds1.Text = dt.Rows[i]["Col4"].ToString();
                    txtmort1.Text = dt.Rows[i]["Col5"].ToString();

                    rowIndex++;
                }
            }
        }
    }

0 个答案:

没有答案