我必须在标签旁边添加一个'[…]作为链接按钮或其他控件,可以进行任何回发。
在我的gridview绑定事件我有这个代码,我有两个包含asp:labels
ItemTemplates
单元格7上的ItemTemplate是不可见的,只是存储了sp调用时绑定的全文。
protected void grid_DataBound( object sender, EventArgs e )
{
GridView grid = (GridView)sender;
GridViewRow header = (GridViewRow)grid.HeaderRow;
GridViewRowCollection rows = (GridViewRowCollection)grid.Rows;
foreach ( GridViewRow row in rows )
{
( (System.Web.UI.WebControls.Label)row.Cells[7].FindControl( "lblAux"
) ).Text = ( (System.Web.UI.WebControls.Label)row.Cells[6].FindControl( "lblText" ) ).Text;
( (System.Web.UI.WebControls.Label)row.Cells[6].FindControl( "lblText" ) ).Text =
( (System.Web.UI.WebControls.Label)row.Cells[6].FindControl( "lblText" ) ).Text.Substring( 0, 10 );
System.Web.UI.WebControls.LinkButton btn = new System.Web.UI.WebControls.LinkButton();
btn.Text = "[...]";
//More code to open a script displaying the full text on popup.
->This doesnt work
row.Cells[6].Add(btn);
I want to be able to add the control next to the label without having to create a new cell, is this possible? if so any help would be appreciated, thanks!.
}
}
我修复了它,如果这种情况发生在别人身上,这是我的解决方案:
在.aspx gridview中,我在包含标签
的相同项模板上添加了linkbutton控件。<asp:TemplateField HeaderText="OBSERVATIONS">
<ItemTemplate>
<asp:Label ID="lblText" runat="server" Text='<%# Bind("OBSERVATIONS") %>' >
</asp:Label>
<asp:LinkButton ID="lnkOpenInDialog" visible="false" runat="server" Text="[...]" OnClick="lnkOpenInDialog_Click"></asp:LinkButton>
</asp:TemplateField>
在"数据绑定"功能中设置链接按钮的命令名。