最近项目中有这样的需求,当GridView 模版列编辑时,有Dropdownlist 和Textbox.TextBox 中的值需要通过
Dropdownlist 选择来动态取得。方法如下:
Dropdownlist 选择来动态取得。方法如下:
Code
DropDownList ddlSource = (DropDownList)sender;
string sourceValue = ddlSource.SelectedValue;
System.Web.UI.WebControls.GridViewRow dvr = (System.Web.UI.WebControls.GridViewRow)ddlSource.NamingContainer; //这是关键.找到当前行
DropDownList ddlGate = (DropDownList)dvr.FindControl("ddlGate");
string gateValue = ddlGate.SelectedValue;
TextBox txtResolution = (TextBox)dvr.FindControl("txtResolution");
if (sourceValue != "-" && gateValue != "-")
{
txtResolution.Text = this.GetResolution(sourceValue, gateValue);
}
else
{
txtResolution.Text = "";
}
DropDownList ddlSource = (DropDownList)sender;
string sourceValue = ddlSource.SelectedValue;
System.Web.UI.WebControls.GridViewRow dvr = (System.Web.UI.WebControls.GridViewRow)ddlSource.NamingContainer; //这是关键.找到当前行
DropDownList ddlGate = (DropDownList)dvr.FindControl("ddlGate");
string gateValue = ddlGate.SelectedValue;
TextBox txtResolution = (TextBox)dvr.FindControl("txtResolution");
if (sourceValue != "-" && gateValue != "-")
{
txtResolution.Text = this.GetResolution(sourceValue, gateValue);
}
else
{
txtResolution.Text = "";
}