我的问题是关于ASP.NET GridView控件。我在Columns标记中使用了CommandField,如下所示。

<asp:CommandField ShowEditButton="True" HeaderStyle-Width="40px" UpdateText="Save" ButtonType="Link" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-Width="40px"/>

渲染的内容如下图所示(单击“编辑”按钮后)。

正如您所看到的我正在尝试让取消链接显示一个新行,我的问题是您如何做?如果我更改 ButtonType =&quot; Link&quot; ButtonType =&quot; Button&quot; ,我正确地渲染它,如下所示。

alt text http://i38.tinypic.com/2pqopxi.jpg

我已经尝试了Google,也许我没有在正确的标签上搜索,但我之前看不到这个问题。

有帮助吗?

解决方案

如果您使用模板字段,它将使您完全控制页面的外观,但它要求您使用CommandName和可能的CommandArgument属性,并且还要使用GridView的OnRowCommand。

aspx页面:

<asp:GridView id="gvGrid" runat="server" OnRowCommand="gvGrid_Command">
 <Columns>
  <asp:TemplateField>
   <ItemTemplate>
    Some Stuff random content
    <br />
    <asp:LinkButton id="lbDoIt" runat="server" CommandName="Cancel"  CommandArgument="SomeIdentifierIfNecessary" />
   </ItemTemplate>
  </asp:TemplateField>
 </Columns>
</asp:GridView>

背后的代码:

protected void gvGrid_Command(object sender, GridViewCommandEventArgs e)
{
 if(e.CommandName=="Cancel")
 {
   // Do your cancel stuff here.
 }

}

其他提示

请勿使用命令字段,请使用 TemplateField 并将命令按钮放在其中,并在其前面添加换行符(br)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top