<asp:TemplateField HeaderText="下拉框">
<ItemTemplate>
<cc1:MyDropDownList ID="ddlPKG" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPKG_SelectedIndexChanged" ToolTip='<%# Eval("id") %>' >
</cc1:MyDropDownList>
</ItemTemplate>
</asp:TemplateField>

 

protected void gvXyPhone_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowIndex != -1)//注意加上这句就OK
{

DropDownList ddlPhoneKG = e.Row.FindControl("ddlPKG") as DropDownList;
ddlPhoneKG.Items.Add(new ListItem("无", "无"));
}

 DataRowView drv = (DataRowView)e.Row.DataItem;

if (drv != null)
{
ddlPhoneKG.SelectedValue = drv.Row["kongguan"].ToString();
}

}

 

//下拉框的值改变

protected void ddlPKG_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlTKG = (DropDownList)sender;
string sqlUpdate = "update table1 set kongguan='" + ddlTKG.SelectedValue + "' where id='" + ddlTKG.ToolTip + "'";
sqlHelp.inUpDelInfo(sqlUpdate);


//GridView.DataSource = dt2;
//GridView.DataBind();

}

 

posted on 2016-04-07 17:16  御不凡  阅读(694)  评论(0编辑  收藏  举报