c# - Can't change properties of LinkButtons in CodeBehind -
i have rlly trouble imo simple thing allready did million times, time, cant.
i have linkbuttons in gridview
<asp:templatefield> <itemtemplate> <asp:linkbutton id="gvcon_tfedit" runat="server" cssclass="eh_label_style" commandargument="edit" commandname="edit" text="edit"></asp:linkbutton> </itemtemplate> </asp:templatefield>
and have 6 times. allways 1 edit , 1 delete-linkbutton.
then try change visible of them in codebehind @ line 5 (if comment out, on 6 etc):
1 protected void page_prerendercomplete(object sender, eventargs e) 2 { 3 if (session["permissions"].tostring() == "user") 4 { 5 gvcomp_tfdelete.visible = false; 6 gvcomp_tfedit.visible = false; 7 gvcon_tfdelete.visible = false; 8 gvcon_tfedit.visible = false; 9 gvmatr_tfdelete.visible = false; 10 gvmatr_tfedit.visible = false;
but allways brings me goodknown exception:
operation not valid due current state of object
well - i'm sure object isnt null there anymore ?! (and session["permissions"] isnt null sure also, because getting status in preload allready ...)
and maybe have tell more, because had problems linkbuttons bevore ^^ - in templatefields had same linkbuttons, changed name of lb, , since couldnt use them in codebehind. because werent in designerfile anymore ... tried alot of tips found evrywhere in inet, tips here - didnt worked (like rebuilding designerfile, writing linkbuttons new aspx-file made sure file in right folder etc ...) nothing worked. added them hand designer.cs. can "use" them in codebehind, when start debugging - runs error.
would nice if me, annoying ...
since using gridview, have use event rowdatabound
gridview.
and in event, have check e.row.rowtype == datacontrolrowtype.datarow
.
after that, can use
linkbutton lb = ((linkbutton)e.row.findcontrol("gvcon_tfedit"));
to linkbutton current row, , use lb.visible = false;
or whatever code need.
Comments
Post a Comment