2009-07-16 16 views
1

我想要做這樣的事情有一個GridView:設置CommandField中選擇公開程度從aspx頁面

<asp:CommandField ShowSelectButton="True" Visible='<%# return Eval("SC_TABLE") %>' /> 

但是,這並不工作,未來與錯誤:

Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.CommandField does not have a DataBinding event.

反正是有我可以從aspx頁面設置可見性? PS:SC_TABLE存在於數據源中,因此該部分沒有任何錯誤。

回答

3

你可以用模板列,而不是做這個...

<asp:TemplateField> 
    <ItemTemplate> 
     <asp:LinkButton runat="server" ID=SelectButton CommandName="SELECT" Visible='<%# Eval("SC_TABLE") %>' Text="Select" /> 
    </ItemTemplate> 
</asp:TemplateField> 
+0

+1:我希望能用CommandField做到這一點。我已經知道這種方式,但它仍然有幫助。哦,看起來CommandField是不可能的。 :( – waqasahmed 2009-07-16 15:30:41

1

我找到了答案,在this post末:

基本上,你需要捕捉RowCreated事件在DataGrid上

OnRowCreated =「GridView1_RowCreated」

然後,在aspx.cs頁面上使用以下代碼隱藏控件:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowIndex == 1) 
    { 
     e.Row.Cells[0].Controls.Clear(); 
    } 
} 

如果在第一列中有一個CommandField,它將起作用。