This is a migrated thread and some comments may be shown as answers.

[Solved] How to Hide after Update using GridEditCommandColumn

5 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sagar
Top achievements
Rank 1
Sagar asked on 26 Mar 2013, 09:22 PM
I have grid like this:

<telerik:RadGrid Width="100%" ID="RadTest" runat="server" AlternatingItemStyle-BackColor="#E4EBEF"
                AllowPaging="true" AllowSorting="true" PageSize="10" ShowStatusBar="true" Skin="WebBlue" AllowAutomaticUpdates ="true" AllowAutomaticInserts ="true"
                GridLines="None" EnableViewState="false" ItemStyle-CssClass="GridText" AlternatingItemStyle-CssClass="GridText">
                <PagerStyle Mode="NextPrevAndNumeric" />
                <GroupingSettings CaseSensitive="false" />
                <MasterTableView Width="100%" AutoGenerateColumns="false" EnableColumnsViewState="false" CommandItemDisplay ="Top"
                    CommandItemSettings-AddNewRecordText = "Add New Item" CommandItemSettings-ShowRefreshButton = "false">
                    <Columns>     
                        <telerik:GridEditCommandColumn  HeaderStyle-Width  = "40px" ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText ="Item">
                        </telerik:GridBoundColumn>
                        <telerik:GridButtonColumn ConfirmDialogHeight = "60" ItemStyle-Width = "70px" ConfirmText="Delete this item?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton"  CommandName="Delete"  Text="Delete" UniqueName="DeleteColumn">
                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton">
                            </ItemStyle>                                   
                        </telerik:GridButtonColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings EnableRowHoverStyle ="true" />
            </telerik:RadGrid>

On the gird, when i click the edit button, i am getting a text box with the value in it and also update and cancel links. I have 2 questions here:

1. After i click update how do i get the text box value below?
2. After i click update i want the update to be done( as shown in the code below) and the edit column(with update and cancel links) should disappear.

Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim item As GridEditFormItem = CType(e.Item, GridEditFormItem)
'code for update
RadTest.DataSource = Nothing
RadTest.Rebind()


Also, as i used CommandItemSettings-AddNewRecordText "Add New Item"
i have button on the top of the grid which says Add new Item. now when i press this i am getting a textbox to add an Item. How do i get the value of this in code behind to insert into db ?

Please  help. Thanks.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Mar 2013, 06:51 AM
Hi,

Try the following code to achieve your scenario.
VB:
Protected Sub RadGrid1_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim txt As TextBox = DirectCast(item("Uniquename").Controls(0), TextBox)
    RadGrid1.MasterTableView.GetColumn("edit").Visible = False
End Sub

Thanks,
Shinu
0
Sagar
Top achievements
Rank 1
answered on 27 Mar 2013, 02:46 PM
Thanks for the reply but it did not work. 

For the text box values it throws an error:
Unable to cast object of type 'System.Web.UI.WebControls.ImageButton' to type 'System.Web.UI.WebControls.TextBox'.

For the second one:
It throws an error: Cannot find a column with UniqueName 'edit'. So i changed it to 
RadGrid1.MasterTableView.GetColumn("EditCommandColumn").Visible = False

but it still did not work. I still see the textbox, update and cancel links after the postback.

0
Shinu
Top achievements
Rank 2
answered on 28 Mar 2013, 05:13 AM
Hi,

Try the following code.
VB:
Protected Sub RadGrid1_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim txt As TextBox = DirectCast(item("Name").Controls(0), TextBox)
    Dim value As String = txt.Text
    'getting new value
    Dim img As ImageButton = DirectCast(item("DeleteColumn").Controls(0), ImageButton)
    img.Visible = False
    'hiding delete column
End Sub

Thanks,
Shinu
0
Sagar
Top achievements
Rank 1
answered on 28 Mar 2013, 09:15 PM
Still not working...

I got the first part where i can get the textbox value. But i cannot hide the Update and cancel links after the postback.

I tried the following to hide after update and it is not working:

Dim img As ImageButton = DirectCast(item("EditCommandColumn").Controls(0), ImageButton)
        img.Visible = False

Also tried this to hide but not working:

Grid.MasterTableView.GetColumn("edit").Visible = False

Can some one please help..
0
Sagar
Top achievements
Rank 1
answered on 29 Mar 2013, 02:25 PM
i fixed it..

item.Edit = False
Tags
Grid
Asked by
Sagar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sagar
Top achievements
Rank 1
Share this question
or