Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

problem with linbutton in edit mode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 31 Jul 2007 13:39 GMT
Hi,

i want to perform several things (like checking and correcting automatically
the lenght of a multiline textbox in order to avoid Truncate error, removing
automatically "<" and "'" to avoid "potential danger" error etc ..) with
javascript on a gridview.

If i take in the aspx file this:
<asp:CommandField ShowEditButton="True">
i have no possibility to use the OnClientClick property.

So i made some Templatefields like this:
<asp:TemplateField><ItemTemplate>
<asp:LinkButton ID="lb1" runat="server" CommandName="Edit"
></asp:LinkButton>
</ItemTemplate></asp:TemplateField>

<asp:TemplateField><EditItemTemplate>
<asp:LinkButton ID="lb2" runat="server" CommandName="Update"
OnClientClick="myfunction();"></asp:LinkButton>
</EditItemTemplate></asp:TemplateField>

<asp:TemplateField><EditItemTemplate>
<asp:LinkButton ID="lb3" runat="server" CommandName="Cancel"
></asp:LinkButton>
</EditItemTemplate></asp:TemplateField>

My problem is now that the linkbutton "Edit" not only appears in normal
mode, but also in Edit mode, together with "Update" and "Cancel"..

I can make it invisible in code-behind, but then there is still an empty
space or column in the gridview.

Any way to solve this?
Thanks
Mark
Teemu Keiski - 31 Jul 2007 17:03 GMT
Hi,

couldn't you just set myGrid.Columns(x).Visible = False where x is the index
of the column  you wish to hide, when you don't want the LinkButton to be
displayed. That would hide the entire column, not just the control.

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

> Hi,
>
[quoted text clipped - 32 lines]
> Thanks
> Mark
Mark - 31 Jul 2007 18:21 GMT
Hi, thanks for replying.

I tried this:

Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit
Then
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lb As LinkButton
lb = e.Row.FindControl("lb2")
lb.Visible = False
...

But there is still an empty column in the selected row and "Edit" is shown
in all not selected rows.

I also tried this:
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit
Then
 GridView1.Columns(1).Visible = False

but this gives the error: Object reference not set to an instance of an
object.

> Hi,
>
[quoted text clipped - 38 lines]
>> Thanks
>> Mark
Teemu Keiski - 31 Jul 2007 20:34 GMT
Hi,

I think cannot use it until the grid has been databound though not 100%
sure. Try after calling DataBind()

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

.

> Hi, thanks for replying.
>
[quoted text clipped - 67 lines]
>>> Thanks
>>> Mark
Teemu Keiski - 31 Jul 2007 20:37 GMT
See: http://fredrik.nsquared2.com/viewpost.aspx?postid=339

E.g try changing cells Visible property but in RowDataBound

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

> Hi, thanks for replying.
>
[quoted text clipped - 67 lines]
>>> Thanks
>>> Mark
Mark - 31 Jul 2007 20:59 GMT
I tried this:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
       If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
           Dim lb As LinkButton
           lb = e.Row.FindControl("lb2")
           lb.Visible = False
       End If
   End Sub
but same result: the column is only empty (with a gap) in the selected row.

I also tried this:

Sub GridView1_DataBound doesn't accept the line:
"   If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then"

It seems to be a though case ...

> See: http://fredrik.nsquared2.com/viewpost.aspx?postid=339
>
[quoted text clipped - 72 lines]
>>>> Thanks
>>>> Mark

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.