为什么Button.CommandArgument的值丢失了?

时间:2011-10-08 14:45:40

标签: asp.net

这是我的代码:

  <asp:GridView ID="AccountBindingDGV"  runat="server"  SkinID="gridviewSkin" 
             OnRowDataBound="AccountBindingDGV_RowDataBound"  ShowFooter="True"  AutoGenerateColumns="False"
             OnDataBound="AccountBindingDGV_DataBound" 
         <Columns>
                      <asp:BoundField DataField="UserName" HeaderText="UserName" />
                      <asp:BoundField DataField="WebsiteAccount" HeaderText="WebsiteAccount" />
                      <asp:TemplateField HeaderText="Remove" ShowHeader="False">
                          <ItemTemplate>
                               <asp:Button ID="Remove" runat="server" Text="Remove" CssClass="ButtonCss1" CommandArgument='<%# Bind("ID") %>'
                                                        OnClick="RemoveButton_Click" OnClientClick="return confirm('Are you sure to REMOVE this account?')" />
                          </ItemTemplate>
                      </asp:TemplateField>   
                      <asp:TemplateField HeaderText="Add" ShowHeader="False">
                           <ItemTemplate>
                                 <asp:Button ID="Add" runat="server" Text="Add" CssClass="ButtonCss1" />
                            </ItemTemplate>
                       </asp:TemplateField>
          </Columns>                      
 </asp:GridView>

我在执行AccountBindingDGV_RowDataBount时执行了一些操作:

enter image description here

我需要Remove.CommandArgument携带的ID来删除一条记录,但它的值为空。我调试AccountBindingDGV_RowDataBount并发现这些删除按钮具有正确的值?我不知道为什么? 有什么好主意吗?

1 个答案:

答案 0 :(得分:-2)

这将有助于您Grid View