2008-10-09 49 views
1

我的问题是在ASP.NET GridView控件上。我在Columns标签中使用了一个CommandField,如下所示。ASP.NET GridView CommandField更新/取消不包装

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

What renders is the shown in the following image (after I click on the Edit button). 

alt text http://i33.tinypic.com/5dpdad.jpg

正如你可以看到我想有取消链接出现一个新行,我的问题是你怎么做呢?如果我将ButtonType =“Link”更改为ButtonType =“Button”,我将它正确渲染,如下所示。

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

我试过谷歌已经和我也许不正确的标签搜索,但我看不出这个人之前解决。

感谢任何帮助。 谢谢。

+0

无法看到你的形象... – Bryant 2008-10-09 17:35:32

回答

3

如果您使用模板字段,它会让您完全控制页面外观,但它要求您使用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. 
} 

}

0

不要使用命令字段,请使用TemplateField,然后将命令按钮放入换行符(br)中,然后像所需的那样。

+0

感谢您的答复科比。但是,它似乎并不适合我。 1-我无法找到绑定CommandField中更新按钮的方法。 - 您无法在CommandTemplate或EditItemTemplate中放置CommandField。还有什么让我担心的是为什么这适用于按钮而不是链接!错误? – user26573 2008-10-09 17:52:09