Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   problem with linbutton in edit mode (http://www.velocityreviews.com/forums/t525929-problem-with-linbutton-in-edit-mode.html)

Mark 07-31-2007 12:39 PM

problem with linbutton in edit mode
 
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 07-31-2007 04:03 PM

Re: problem with linbutton in edit mode
 
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.


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


"Mark" <mark@fit.pm> wrote in message
news:uLABk$20HHA.484@TK2MSFTNGP06.phx.gbl...
> 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
>




Mark 07-31-2007 05:21 PM

Re: problem with linbutton in edit mode
 
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.


"Teemu Keiski" <joteke@aspalliance.com> schreef in bericht
news:O7xWqx40HHA.1208@TK2MSFTNGP03.phx.gbl...
> 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.
>
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
>
> "Mark" <mark@fit.pm> wrote in message
> news:uLABk$20HHA.484@TK2MSFTNGP06.phx.gbl...
>> 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 07-31-2007 07:34 PM

Re: problem with linbutton in edit mode
 
Hi,

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

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

..


"Mark" <mark@fit.pm> wrote in message
news:On9HTd50HHA.3768@TK2MSFTNGP06.phx.gbl...
> 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.
>
>
> "Teemu Keiski" <joteke@aspalliance.com> schreef in bericht
> news:O7xWqx40HHA.1208@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>>
>> --
>> Teemu Keiski
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice.com/joteke
>> http://teemukeiski.net
>>
>>
>> "Mark" <mark@fit.pm> wrote in message
>> news:uLABk$20HHA.484@TK2MSFTNGP06.phx.gbl...
>>> 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 07-31-2007 07:37 PM

Re: problem with linbutton in edit mode
 
See: http://fredrik.nsquared2.com/viewpost.aspx?postid=339

E.g try changing cells Visible property but in RowDataBound

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



"Mark" <mark@fit.pm> wrote in message
news:On9HTd50HHA.3768@TK2MSFTNGP06.phx.gbl...
> 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.
>
>
> "Teemu Keiski" <joteke@aspalliance.com> schreef in bericht
> news:O7xWqx40HHA.1208@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>>
>> --
>> Teemu Keiski
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice.com/joteke
>> http://teemukeiski.net
>>
>>
>> "Mark" <mark@fit.pm> wrote in message
>> news:uLABk$20HHA.484@TK2MSFTNGP06.phx.gbl...
>>> 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
>>>

>>
>>

>
>




Mark 07-31-2007 07:59 PM

Re: problem with linbutton in edit mode
 
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 ...



"Teemu Keiski" <joteke@aspalliance.com> schreef in bericht
news:eKQbxo60HHA.728@TK2MSFTNGP05.phx.gbl...
> See: http://fredrik.nsquared2.com/viewpost.aspx?postid=339
>
> E.g try changing cells Visible property but in RowDataBound
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
>
>
> "Mark" <mark@fit.pm> wrote in message
> news:On9HTd50HHA.3768@TK2MSFTNGP06.phx.gbl...
>> 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.
>>
>>
>> "Teemu Keiski" <joteke@aspalliance.com> schreef in bericht
>> news:O7xWqx40HHA.1208@TK2MSFTNGP03.phx.gbl...
>>> 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.
>>>
>>>
>>> --
>>> Teemu Keiski
>>> AspInsider, ASP.NET MVP
>>> http://blogs.aspadvice.com/joteke
>>> http://teemukeiski.net
>>>
>>>
>>> "Mark" <mark@fit.pm> wrote in message
>>> news:uLABk$20HHA.484@TK2MSFTNGP06.phx.gbl...
>>>> 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
>>>>
>>>
>>>

>>
>>

>
>





All times are GMT. The time now is 10:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.