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

Editing from a radGrid

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sintayehu
Top achievements
Rank 1
Sintayehu asked on 05 Sep 2008, 06:39 PM
I am working on a proj. where I have to use two edit buttons on a RadGrid.

one regular edit button that will edit every column, <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>

and one that is to be used as a replace user.


<
telerik:GridButtonColumn UniqueName="ReplaceCommandColumn" CommandName="Edit" Text="Replace"></telerik:GridButtonColumn>

I am basically trying to acomplish replacing one user account with another in my database.

The problem I am having is since my replace button is using edit as its commandName it is returning all the columns for edit as opposed to specific ones I want.

I just want it to return two fields when I replace, and all fields when I edit.

Is there a way to customize the edit command? Since it is the one that is returning all the field. If not is there a better approach?

3 Answers, 1 is accepted

Sort by
0
Raj
Top achievements
Rank 1
answered on 05 Sep 2008, 07:05 PM
Check this link for handling custom commands :
http://www.telerik.com/help/aspnet/grid/grdcommanditemtemplate.html


Also to set the grid in edit mode in your command handler add the following :
private void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) {
if ((e.CommandName == "ReplaceCommand")) {
 e.Item.Edit = true;
 e.Item.OwnerTableView.Rebind();

// here you can hide controls which are not to be shown


}}

0
Sintayehu
Top achievements
Rank 1
answered on 08 Sep 2008, 03:16 PM
Hi, I am having problem accessing the controls in the editForm so I can hide them.

Do you have an example?

It looks like I need to change the editForm setting but I didn't see how.

e.Item.OwnerTableView.EditFormSettings. ????

For example In my aspx page I have several columns that look like the code down below 

From my code behind I would like to hide the password and confirm password text boxes.

But  I can't use something like

PasswordTextBox.visible = false;

Because my code behind does not see it since it is in the Edittemplate tag.

How can I get to it is my Question?

<telerik:GridTemplateColumn

DataField
="Password" HeaderText="Password" SortExpression="Password"UniqueName="Password" Visible="False" Display="False"><ItemTemplate><asp:Label ID="PasswordLabel" runat="server" Text='<%# Eval("Password", "{0:C}") %>'></asp:Label></ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID="PasswordTextBox" runat="server" Text='<%# Bind("Password") %>' TextMode="Password"CausesValidation="False"></asp:TextBox><asp:RequiredFieldValidator ID="PasswordRequiredFieldValidator" runat="server" ErrorMessage="Please enter password."ControlToValidate="PasswordTextBox"></asp:RequiredFieldValidator><asp:Label ID="ConfirmPasswordLabel" runat="server" Text="ConfirmPassword:"></asp:Label><asp:TextBox ID="ConfirmPasswordTextBox" runat="server" Text='<%# Bind("ConfirmPassword") %>'TextMode="Password" CausesValidation="False"></asp:TextBox><asp:CompareValidator ID="PasswordCompareValidator" runat="server" ErrorMessage="Passwords do not match."ControlToCompare="ConfirmPasswordTextBox" ControlToValidate="PasswordTextBox"></asp:CompareValidator>

</
EditItemTemplate>

</
telerik:GridTemplateColumn>

0
Raj
Top achievements
Rank 1
answered on 08 Sep 2008, 04:42 PM
that can be done in On Item Created event or ItemDataBound of Grid as follows :

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)

{

if (e.Item.IsInEditMode == true)

{

GridEditableItem editItem = e.Item as GridEditableItem;

RadComboBox rcbControl = editItem["ColumnUniqueName"].FindControl("RadComboBox1") as RadComboBox;

rcbControl.Visible = false;
}

}

Tags
Grid
Asked by
Sintayehu
Top achievements
Rank 1
Answers by
Raj
Top achievements
Rank 1
Sintayehu
Top achievements
Rank 1
Share this question
or