Skip to main content
 首页 » 编程设计

c#之选择按钮之ASP.NET 中 GridView 上的 CommandField

2024年02月23日14kerrycode

我有下面的代码在网页上创建一个 GridView。我试图禁用 SelectButton 或使其不可见,或者只是删除它。我试过了

AutoGenerateSelectButton="false" 

和

<asp:CommandField SelectText="Seç" Visible="false" 
                                                                        ShowSelectButton="True"  /> 

我什至删除了这部分

<Columns> 
          <asp:CommandField          SelectText="Seç"                                                                            ShowSelectButton="True" /> 
 </Columns>  

它们都不起作用,SelectButton 仍然存在。 我试图用

将它的 SelecText 更改为 Aç
<asp:CommandField SelectText="Aç"                                                                            ShowSelectButton="True" /> 

这个也不好用,我也试过了

ShowSelectButton="False" and it didn't change anything. 
 
   <asp:UpdatePanel ID="UpdatePanelEnCokSatilanUrunler" runat="server"> 
             <ContentTemplate> 
                      <asp:Panel ID="PanelEnCokSatilanUrunler" runat="server"  
                      GroupingText="En Çok Satılan Ürünler"  
                      BorderWidth="1" Font-Bold="true"> 
                           <table class="style1"> 
                               <tr> 
                                  <td> 
                                      <asp:GridView ID="GridView_EnCokSatilanUrunler"  
                                      runat="server" 
                           OnRowDataBound="GridView_EnCokSatilanUrunler_RowDataBound" 
                                       Font-Bold="false" 
           OnSelectedIndexChanged="GridView_EnCokSatilanUrunler_SelectedIndexChanged" 
                                       AllowSorting="true" 
                                     OnSorting="GridView_EnCokSatilanUrunler_Sorting"> 
                                            <Columns> 
                                                 <asp:CommandField SelectText="Seç" 
                                                     ShowSelectButton="True"/>   
                                            </Columns>          
                                  </asp:GridView> 
                     </td> 
                    </tr> 
                 </table> 
               </asp:Panel> 
 
              </ContentTemplate> 
 
            </asp:UpdatePanel> 

这是我在 aspx.cs 中的内容,它对 SelectButton

没有任何作用
protected void GridView_EnCokSatilanUrunler_SelectedIndexChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        protected void GridView_EnCokSatilanUrunler_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.Header) 
            { 
                ((LinkButton)e.Row.Cells[1].Controls[0]).Text = "Ürün No"; 
                ((LinkButton)e.Row.Cells[2].Controls[0]).Text = "Ürün Adı"; 
                ((LinkButton)e.Row.Cells[3].Controls[0]).Text = "Satış Miktarı"; 
                ((LinkButton)e.Row.Cells[4].Controls[0]).Text = "Ürün Durum"; 
                ((LinkButton)e.Row.Cells[5].Controls[0]).Text = "Ürün Tipi"; 
                ((LinkButton)e.Row.Cells[6].Controls[0]).Text = "Marka"; 
                ((LinkButton)e.Row.Cells[7].Controls[0]).Text = "Model";                 
            } 
            else if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
 
            } 
        } 
 
        protected void GridView_EnCokSatilanUrunler_Sorting(object sender, GridViewSortEventArgs e) 
        { 
            if (EnCokSatilanUrunlerSortColumn == e.SortExpression) 
            { 
                if (EnCokSatilanUrunlerSortDirection) 
                    EnCokSatilanUrunlerSortDirection = false; 
                else if (!EnCokSatilanUrunlerSortDirection) 
                    EnCokSatilanUrunlerSortDirection = true; 
            } 
            else 
                EnCokSatilanUrunlerSortDirection = true; 
 
            EnCokSatilanUrunlerSortColumn = e.SortExpression; 
 
            EnCokSatilanUrunlerPageIndex = 0; 
 
            GridView_EnCokSatilanUrunler.SelectedIndex = -1; 
 
 
        } 
 
        void EnCokSatilanUrunlerGridDoldur() 
        { 
            GridView_EnCokSatilanUrunler.DataSource = DAL.raporx.DAOUrunx.GetEnCokSatilanBesUrun( 
                                                                                                    DateTime.Now - new TimeSpan(30, 0, 0, 0), 
                                                                                                    DateTime.Now 
                                                                                                ); 
 
            GridView_EnCokSatilanUrunler.DataBind(); 
        } 

我只想要一个没有 SelectButton 的 GridView。

请您参考如下方法:

删除特定行的选择:

在 RowDatBound 中

e.Row.Cells[0].Controls[0].Visible = false;