简体   繁体   English

在asp.net gridview控件的模板字段中隐藏链接按钮

[英]Hiding linkbutton in template field in asp.net gridview control

So I have a button as following on the picture: 所以我在图片上有一个如下按钮:

在此处输入图片说明 So when I press this link button (which is located in template field inside of grid control), I would like to hide it and show a combo box instead of it where user can pick up the status. 因此,当我按下此链接按钮(位于网格控件内部的模板字段中)时,我想隐藏它并显示一个组合框,而不是供用户选择状态的组合框。

I have created the following code for that: 我为此创建了以下代码:

    if (e.CommandName == "IzmjeniStatus")
                {
                    string[] arg = e.CommandArgument.ToString().Split(';');
                    int index = Convert.ToInt32(arg[1].ToString());
// first locating the combo box inside of template field
                    DropDownList ComboStatus = (DropDownList)gridKorisnici.Rows[index].FindControl("DropDownList1");
// then locating the button
                    LinkButton btnIzmjeniStatus = (LinkButton)gridKorisnici.Rows[index].FindControl("btnStatusKorusnika");
                    btnIzmjeniStatus.Visible = false;
                    ComboStatus.Visible = true;
// once the button is pressed, hide the button and show the dropdown list

                    int KupacID = Convert.ToInt32(arg[0].ToString());
                    hsp_Kupci_SelectByID_Result k = ServisnaKlasa.KupacByID(KupacID);
                    if(k.Status==true)
                    {
                        ServisnaKlasa.UpdateStatusKorisnika(KupacID, false);
                    }
                    else
                    {
                        ServisnaKlasa.UpdateStatusKorisnika(KupacID, true);
                    }
                    BindGrid();
                }

This is the aspx code of grid: 这是网格的aspx代码:

 <asp:GridView ID="gridKorisnici" AutoGenerateColumns="false" AllowPaging="true" PageSize="20" runat="server" OnRowCommand="gridKorisnici_RowCommand" OnRowDataBound="gridKorisnici_RowDataBound" OnPageIndexChanging="gridKorisnici_PageIndexChanging">
        <Columns>
            <asp:BoundField DataField="Ime" HeaderText="Ime"/>
            <asp:BoundField DataField="Prezime" HeaderText="Prezime" />
            <asp:BoundField DataField="Email" HeaderText="Email"/>
            <asp:CheckBoxField DataField="Popust" HeaderText="Popust"/>
            <asp:BoundField DataField="IznosPopusta" HeaderText="Iznos popusta(%)"/>
            <asp:CheckBoxField DataField="Status" HeaderText="Aktivan"/>
            <asp:TemplateField HeaderText="Unos popusta(%)">
                <ItemTemplate>
                    <asp:TextBox ID="txtPopust2" runat="server"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                     <asp:LinkButton ID="btnPopust" runat="server" Title="Aktivacija popusta" CommandName="AktivirajPopust"  CommandArgument='<%#Eval("KupacID") + ";" +((GridViewRow) Container).RowIndex%>' ><img   src="../images/1popust.png" /></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
              <asp:TemplateField>
                <ItemTemplate>
                     <asp:LinkButton ID="btnDeaktivirajPopust" Title="Deaktivacija popusta" runat="server" CommandName="DeaktivirajPopust" CommandArgument='<%# Eval("KupacID") %>'><img  src="../images/1popustminus.png" /></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
               <asp:TemplateField>
                <ItemTemplate>
                     <asp:LinkButton ID="btnStatusKorusnika" title="Izmjeni status" runat="server" CommandName="IzmjeniStatus" CommandArgument='<%#Eval("KupacID") + ";" +((GridViewRow) Container).RowIndex%>'><img   src="../images/1status.png" /></asp:LinkButton>
                    <asp:DropDownList ID="DropDownList1" Visible="false" runat="server"></asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
               <asp:TemplateField>
                <ItemTemplate>
                     <asp:LinkButton ID="btnHistorijaPristupa" title="Historija pristupa" runat="server" CommandName="HistorijaPristupaCommand" CommandArgument='<%# Eval("KupacID") %>'><img src="../images/1logovi.png" /></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

What am I doing wrong here, can someone help me out with this?? 我在这里做错了什么,有人可以帮我解决这个问题吗?

Thanks. 谢谢。

如果我没有记错的话,这里的方法是BindGrid(),它将网格视图带到初始状态,在该状态下,您已将组合框的visible属性设置为'false',尝试删除BindGrid()并检查是否可以看到组合框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM