所以我在图片上有一个按钮如下:
因此,当我按下此链接按钮(位于网格控件内的模板字段中)时,我想隐藏它并显示一个组合框而不是用户可以获取状态的组合框。
我为此创建了以下代码:
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();
}
这是网格的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>
我在这里做错了什么,有人可以帮我解决这个问题吗?
感谢。
答案 0 :(得分:1)
如果我没有错,方法BindGrid()就是这里的问题,它将gridview带到初始状态,你已经将组合框的visible属性设置为'false',尝试删除BindGrid()并检查是否你可以看到组合框。