2

DDL OnSelectedIndexChanged イベントの後に griview でコントロールを見つけたいです。ターゲット コントロールは、DDL が配置されている行インデックスにあります。

ここに私のコード;

protected void Page_Load(object sender, EventArgs e)
{
    ArrayList Dummysource = new ArrayList() { "AA", "BB", "CC", "DD" };

    if(!IsPostBack )
    {
        GridView1.DataSource = Dummysource;
        GridView1.DataBind();  
    }

}

protected void ddlsample_OnSelectedIndexChanged(object sender, EventArgs e)
{
    string valueComponent = (sender as DropDownList).SelectedItem.Value;


    Label1.Text = valueComponent;

}


int ddlvalue;
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    //Checking whether the Row is Data Row
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //Finding the Dropdown control.
        DropDownList ddlsample = (DropDownList)e.Row.FindControl("ddlsample");
        Label ilbldata = (Label)e.Row.FindControl("lbldata");

        if (ddlsample != null)
        {
            switch(ilbldata.Text) 
            {

                case "AA":
                    ddlvalue = 2;
                    break;
                case "BB":
                    ddlvalue = 3;
                    break;
                case "CC":
                    ddlvalue = 4;
                    break;
                case "DD":
                    ddlvalue = 5;
                    break;  

            }
            for (int i = 1; i <= ddlvalue; i++ )
            {
                ddlsample.Items.Add(i.ToString() );   
            }
        }
    }

}

protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)

{
    GridView gv = sender as GridView;
    gv = GridView1; 
    Label  foo = gv.SelectedRow.FindControl("lbldata") as Label ;
    Label2.Text = foo.Text;  
}

このコードは、DropDownList で選択されたアイテムの値を取得します。グリッドビューでコンポーネントの値を取得する方法について疑問に思っています。DDL の selectedindexchange イベントの後

より明確にするために視覚的な写真を作成しました http://i1288.photobucket.com/albums/b493/Kasparov1/GridviewDDL_zps3721fb97.png

前もって感謝します;

4

2 に答える 2

3

これを試して

protected void ddlsample_OnSelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;

    Label1.Text = ddl.SelectedItem.Value;

    GridViewRow row = (GridViewRow)ddl.NamingContainer;

   // Find your control
   Control control = row.FindControl("myControl");
}
于 2013-05-15T01:28:18.423 に答える
0
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
   DropDownList drop = GridView1.Controls[0].Controls[0].FindControl("DropDownList1") as DropDownList;
   string text = drop.Items[drop.SelectedIndex].ToString();
   //Find FooterRow Control
   DropDownList dT = GridView1.FooterRow.FindControl("DropDownList1") as DropDownList;
   string text = dT.Items[dT.SelectedIndex].ToString();
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)//DropDownList1 in GridVied 
{
    //Find FooterRow Control
    DropDownList drop = GridView1.FooterRow.FindControl("DropDownList1") as DropDownList;
    string text = drop.Items[drop.SelectedIndex].ToString();
    //find normal DropDownList1
    DropDownList drop1 = GridView1.FindControl("DropDownList1") as DropDownList;
    string text = drop1.Items[drop1.SelectedIndex].ToString();
 }

//ADD list in GRIDVIEW dropdownlist at run time

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");//Gridview DropDownList
   ddl.Items.Add("- - Select - -");
   ddl.Items.Add(new ListItem("ABCD"));
   ddl.Items.Add(new ListItem("EFGH"));
}
于 2013-05-15T06:53:25.130 に答える