试试这个:为 ColB 使用 TemplateField 并同时放置 TextBox 和 DropdownList
<asp:TemplateField HeaderText="ColB">
<asp:TextBox runat="server" ID="txtVal" />
<asp:DropdownList runat="server" ID="drpVal"></asp:DropdownList>
</asp:TemplateField>
在您的 gridview 的数据绑定中执行此操作
void myGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
TextBox txtVal = (TextBox)e.Row.FindControl("txtVal");
DropDownList drpVal = (DropDownList)e.Row.FindControl("drpVal");
if (txtVal != null && drpVal != null)
{
if (condition == true)
{
txtVal.Text = "Default value";
drpVal.Visible = false;
}
else
{
drpVal.Items.Add("Item1");
drpVal.Items.Add("Item2");
drpVal.Items.Add("Item3");
txtVal.Visible = false;
}
}
}