C# 如何在c中读取项目模板字段#
我有一个下拉框内的项目模板。根据我的要求,我需要更新aspx.cs页面中下拉列表的工具提示字段 我使用以下代码:C# 如何在c中读取项目模板字段#,c#,asp.net,C#,Asp.net,我有一个下拉框内的项目模板。根据我的要求,我需要更新aspx.cs页面中下拉列表的工具提示字段 我使用以下代码: <asp:TemplateField HeaderStyle-CssClass="grid-label-small" HeaderText="*State"> <ItemTemplate> <asp:DropDownList ID="ddlDefState" Width="110px" runat="server" ToolTip="Sele
<asp:TemplateField HeaderStyle-CssClass="grid-label-small" HeaderText="*State">
<ItemTemplate>
<asp:DropDownList ID="ddlDefState" Width="110px" runat="server" ToolTip="Select State">
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle CssClass="grid-label-small" />
</asp:TemplateField>`.
`.
谢谢…将GridView的RowDataBound事件用作:
void TitleGridView_RowDataBound (Object sender, GridViewRowEventArgs e)
{
// Get the RadioButtonList control from the row.
RadioButtonList radio = (RadioButtonList)e.Row.FindControl("TypeList");
// To Get DropDownList Cast as DropDownList and Find with it's Id - ddlDefState
DropDownList list = (DropDownList )e.Row.FindControl("ddlDefState");
有关详细信息,请检查此属性。您好,如果您在RowDataBound事件中绑定,则可以使用此属性找到项模板控件。将OnRowDataBound事件添加到GridView,如下所示
<asp:GridView runat="server" OnRowDataBound="grd_RowDataBound" ></asp:GridView>
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropDown;
dropDown= e.Row.FindControl("ddlDefState") as DropDownList;
if (dropDown!= null)
// Write your code here
}
}
受保护的void grd_RowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
下拉列表;
dropDown=e.Row.FindControl(“ddlDefState”)作为DropDownList;
如果(下拉菜单!=null)
//在这里编写代码
}
}
或者,您也可以通过这种方式从asp:GridView标记绑定到工具提示
<asp:TemplateField HeaderStyle-CssClass="grid-label-small" HeaderText="*State">
<ItemTemplate>
<asp:DropDownList ID="ddlDefState" Width="110px" runat="server"
ToolTip="<%# Bind("Your Property Name") %>">
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle CssClass="grid-label-small" />
</asp:TemplateField>
希望这有帮助。感谢您为GridView处理事件,如:
<asp:GridView runat="server" id="gvData" OnRowDataBound="gvData_RowDataBound">
<HeaderStyle CssClass="grid-label-small" />
<Columns>
<asp:TemplateField HeaderStyle-CssClass="grid-label-small" HeaderText="*State">
<ItemTemplate>
<asp:DropDownList ID="ddlDefState" Width="110px" runat="server"
ToolTip="Select State">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我可以知道在哪里调用函数grd_RowDataBound(对象发送器,GridViewRowEventArgs e)吗?有没有办法在不使用grid view的情况下更改工具提示文本?
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlDefState;
ddlDefState = (DropDownList)e.Row.FindControl("ddlDefState");
if (ddlDefState != null)
{
ddlDefState.ToolTip = "Your New Tooltips";
// Write your other code here
}
}
}