从网格视图中获取每行的选定索引更改事件

时间:2013-09-06 11:49:59

标签: asp.net gridview

我曾尝试在网格视图中绑定动态创建的下拉列表,并为其添加了所选的索引更改事件,但是当我有第一行下拉列表的更改值时,它会给我输出。我希望单个行选择索引更改事件我该怎么办?

我在更新面板中选择了网格视图,并在网格视图中添加了动态下拉列表,并为每一行绑定了它。现在我想为每个行下拉列表添加选定的索引更改事件。我的代码如下: -

for (int i = 0; i < gv_details.Rows.Count; i++)
{
    DropDownList ddl_Hotel = new DropDownList();  
    ddl_Hotel.ID = "ddl_Hotel_" + i;
    //add TextBox to the first column
    string loc = gv_details.Rows[i].Cells[3].Text.ToString();
    string selecctloc = "select locid from loc_master where location='" + loc + "'";

    SqlDataReader dr = cdf.Execute_SelectForDR(selecctloc);
    dr.Read();
    string loc_id = dr["locid"].ToString();
    dr.Close();

    string bind_hotelList = "SELECT Hotel_Id,Hotel_Name FROM Mast_Hotel WHERE LocId ='" + loc_id + "'";
    cdf.Bind_DropDownList(ddl_Hotel, bind_hotelList, "Hotel_Name", "Hotel_Id");
    //ddl_Hotel.Items.Add(new ListItem("Select", "0"));
    ddl_Hotel.Items.Insert(0, new ListItem("---Select---", "0"));
    ddl_Hotel.SelectedValue = "0";
    gv_details.Columns[5].Visible = true;


    ddl_Hotel.SelectedIndexChanged += new EventHandler(ddl_Hotel_SelectedIndexChanged);
    this.Form.Controls.Add(ddl_Hotel);
    UpdatePanel1.ContentTemplateContainer.Controls.Add(ddl_Hotel);
    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
    trigger.ControlID = ddl_Hotel.ID;
    trigger.EventName = "SelectedIndexChanged";
    UpdatePanel1.Triggers.Add(trigger);
    ddl_Hotel.AutoPostBack = true;
    gv_details.Rows[i].Cells[5].Controls.Add(ddl_Hotel);
    //  ddl_Hotel.Attributes.Add("onchange", "retun destination_name()");
} 
请告诉我答案。

0 个答案:

没有答案