Hiding linkbutton in template field in asp.net gridview control

1.4k views Asked by At

So I have a button as following on the picture:

enter image description here 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:

 <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.

1

There are 1 answers

0
asp.netGhost On BEST ANSWER

If i am not wrong the method BindGrid() is the problem here,it brings the gridview to the initial state where you have set the combo box's visible property to 'false' ,try to remove the BindGrid() and check if you are able to see the combobox.