c# - Can I programmatically add a linkbutton to gridview? -


I am looking for some similar questions without any luck. What I want to do is a gridview that shows a link button for some items and shows a hyperlink for other items. I currently have this code:

  public zero gv_RowDataBound (the object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {var Data = (FileDirectoryInfo) e .Row.DataItem; Var IMG = New System Web. UI. Html control HTML image (); If (data length == faucet) {img.Src = "/images/folder.jpg"; Var lnk = new link button (); Lnk.ID = "lnkFolder"; Lnk.Text = data.Name; Lnk.Command + = New CommandEventHandler (changeFolder_OnCommand); Lnk.CommandArgument = data.Name; E.Row.Cells [0] .Controls.Add (lnk); } And {var lnk = new hyperlink (); Lnk.Text = data.Name; Lnk.Target = "_blank"; Lnk.NavigateUrl = getLink (data.Name); E.Row.Cells [0] .Controls.Add (lnk); Img.Src = "/images/file.jpg"; } E. Ro Seals [0]. Control. AddAt (0, IMG); }}  

Where the first cell is a TemplateField. At present, everything is displayed correctly, but linkbutton commands do not increase event handlers, and all controls disappear on postback.

Any thoughts?

After the

I think you should try to rebind the GridView > postback try needed. This will ensure that any dynamic controls were rebuilt and their event handler was re-connected.

Callback on IOW, gridview on callback.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -