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

Change Edit Form control properties dynamically

3 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iris
Top achievements
Rank 1
Iris asked on 30 Jul 2012, 04:24 AM
I have two types of users for the website, admin and non-admin. Both users can edit the data using the edit form, but only admin can edit the password textbox. I plan to make the text box visible only to the admin

During painting the edit form, the application should check whether the user is an admin (using a variable stored in Default.aspx.cs) and change the value for the Visible properties for the textbox accordingly.

<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Password") %>' Visible='<%# if (loggedInUser == admin) {true;} else {false;} %>' ></asp:TextBox>


Can anyone tell me how to do this. The code above wouldn't compile and I'm a newbie in web programming.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Iris
Top achievements
Rank 1
answered on 30 Jul 2012, 04:38 AM
-deleted text-
0
Accepted
Shinu
Top achievements
Rank 2
answered on 30 Jul 2012, 06:19 AM
Hello,

You can check for the cell text in edit mode and set the visibility of the textbox accordingly. Here is the sample code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
 {
   GridEditFormItem item = e.Item as GridEditFormItem;
   TextBox txt = (TextBox)item.FindControl("TextBox2");
   TextBox txtadmin = (TextBox)item["UniqueName"].Controls[0];
   if (txtadmin.Text == "admin")
   {
    txt.Visible = true;
   }
   else
   {
     txt.Visible = false;
   }
}

Thanks,
Shinu.
0
Iris
Top achievements
Rank 1
answered on 02 Aug 2012, 03:33 AM
It perfectly solves the problem. Thank you.
Tags
Grid
Asked by
Iris
Top achievements
Rank 1
Answers by
Iris
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or