日期:2014-05-18  浏览次数:20419 次

50分求GridView+DropDownList 问题 急!!!!
在gridview中最后一列放了模板列里面添加了一个dropdownlist控件。
想让dropdownlist的值改变时,对dropdownlist所在的行进行操作,
请教怎样获取dropdownlist所在行的索引???

------解决方案--------------------
我的方法有些复杂,不知道你能否接受
方法1
1. 给按钮CommandName 假设为Test
2. 在GridView1_RowCreated,把当前行索引赋给按钮的CommandArgument属性

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton addButton ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
addButton = (LinkButton)e.Row.Cells[1].Controls[0];
if (addButton != null)
{
if (addButton.CommandName== "Test ")
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
}
3. 在GridView1_RowCommand中进行处理...
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Test ")
{
Response.Write(((Label)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Controls[1]).Text);
}
}