3 Answers, 1 is accepted
0
Accepted

Shinu
Top achievements
Rank 2
answered on 20 Aug 2012, 04:22 AM
Hi Tina,
Try the following code snippet to show the gridboundcolumn as a hyperlink.In the case of adding controls to the cells of GridBoundColumn,you cannot use ItemCreated only, but a combination of ItemCreated and ItemDataBound. This is due to the fact that the control created in ItemCreated will be erased when data-binding this control. Also, if you create the control in ItemDataBound when the controls are created from ViewState, the grid will not raise ItemDataBound, and the control will not be created and would not raise postback events. The solution for such cases is to create the control in ItemDataBound and recreate this control if needed on ItemCreated for subsequent postbacks.
C#:
Thanks,
Shinu.
Try the following code snippet to show the gridboundcolumn as a hyperlink.In the case of adding controls to the cells of GridBoundColumn,you cannot use ItemCreated only, but a combination of ItemCreated and ItemDataBound. This is due to the fact that the control created in ItemCreated will be erased when data-binding this control. Also, if you create the control in ItemDataBound when the controls are created from ViewState, the grid will not raise ItemDataBound, and the control will not be created and would not raise postback events. The solution for such cases is to create the control in ItemDataBound and recreate this control if needed on ItemCreated for subsequent postbacks.
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink link =
new
HyperLink();
link.Text = item[
"UniqueName"
].Text;
//accessing the GridBoundColumn to get the text
link.NavigateUrl =
"Radgrid1.aspx"
;
item[
"UniqueName"
].Controls.Add(link);
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink link =
new
HyperLink();
link.Text = item[
"UniqueName"
].Text;
//accessing the GridBoundColumn to get the text
link.NavigateUrl =
"Radgrid1.aspx"
;
item[
"UniqueName"
].Controls.Add(link);
}
}
Thanks,
Shinu.
0

Tina
Top achievements
Rank 1
answered on 20 Aug 2012, 04:29 PM
Thanks, It works.I want to show a symbol(*) as required in edit mode not required field validator.but to show th field is mandatory.Can you share your thoughts?
0

Shinu
Top achievements
Rank 2
answered on 21 Aug 2012, 03:59 AM
Hi Tina,
I suppose you want to show a '*' symbol in the right side of the TextBox(BoundColumn in edit mode). Please try the following code snippet.
C#:
Thanks,
Shinu.
I suppose you want to show a '*' symbol in the right side of the TextBox(BoundColumn in edit mode). Please try the following code snippet.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
Label lbl =
new
Label();
lbl.Text =
"*"
;
lbl.ForeColor = Color.Red;
edit[
"UniqueName"
].Controls.Add(lbl);
}
}
Thanks,
Shinu.