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

[Solved] How to Dynamically get Label text in EditFormSettings in a RadGrid

3 Answers 589 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 28 Jul 2009, 07:40 PM
Hello,
I am getting errors on getting a label text value (in EditFormSettings) from the code behind '<%# DataBinder.Eval(Container,"SIDX1H") %>'
in the aspx page. Please see the code below...
I have tried Container.DataItem also but still error.
Any solutions to get the value correctly?
Also Can I get the row header (column) value in the EditFormSettings ?

Here is the Code Behind for Grid Item Command:

 

Protected Sub gv_Search_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gv_Search.ItemCommand

 

 

'Get the Row index of the click and load the DataKeys (Columns)

 

 

Dim index As Int32 = Convert.ToInt32(e.Item.ItemIndex)

 

 

Select Case e.CommandName

 

 

Case "edit"

 

 

Dim SIDX1H As String = _user.Containers(0).CustomView.SIDX1.ToString ..........

 


Here is the aspx code for Editformsettings:

<

 

EditFormSettings EditFormType="Template">

 

 

<EditColumn ButtonType="LinkButton" CancelText="Cancel" InsertText="Insert Order" UniqueName="col_Edit" UpdateText="Update">

 

 

<ItemStyle BackColor="Black" />

 

 

</EditColumn>

 

 

<FormTemplate>

 

 

<div class="divGVEdit" style="padding-left: 10px;">

 

 

<div style="padding-left: 10px; text-align: left">

 

 

<table id="tblReg" style="border-collapse: collapse;" cellspacing="2" cellpadding="1">

 

 

<tr>

 

 

<td align="left">

 

 

<itemtemplate>

 

 

<asp:Label ID="lbl1" runat="server" Text='<%# DataBinder.Eval(Container,"SIDX1H") %>' />

 

 

</itemtemplate>...........

 


Thanks
Sanjay

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2009, 05:49 AM
Hello Sanjay,

You cannot access the label placed inside a form template in the EditCommand(code behind) of the grid. Instead you can try accessing the label in the ItemDataBound event of the grid:
aspx:
<EditFormSettings EditFormType="Template"
     <FormTemplate> 
          <table id="tblReg" style="border-collapse: collapse;" cellspacing="2" cellpadding="1"
              <tr> 
                 <td align="left">                      
                     <asp:Label ID="lbl1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"SIDX1H") %>' />                    
                 </td> 
              </tr> 
           </table> 
      </FormTemplate> 
</EditFormSettings> 

c#:
protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            Label lbl = (Label)editItem.FindControl("lbl1"); 
            
        } 
    } 

Thanks
Princy.
0
Sanjay
Top achievements
Rank 1
answered on 29 Jul 2009, 06:07 PM

HI Princy,

 

Thanks for your reply! The solution to access the label in the ItemDataBound event of the grid is working fine. But there was the same error if I left the label Text='<%# DataBinder.Eval(Container.DataItem,"SIDX1H") %>'. So I replace with Text='' and let the code behind
(as per you c# code) take care of it. I added the line :
lbl.Text = _user.Containers(0).CustomView.SIDX1.ToString() as the last line in the if {} block.

I wanted to know : Can I directly access the row header (columnname )  of the radgrid value in the EditFormSettings  or ItemDataBound? If so how?

Many Thanks,
Sanjay

 

 

0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Jul 2009, 09:14 AM
Hello Sanjay,

You can access the column header in the ItemDataBound event of the grid as shown below:
c#:
protected void gv_Search_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
            string strtxt = headerItem["ColumnUniqueName"].Text
        } 
    } 

Regards
Princy.
Tags
Grid
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sanjay
Top achievements
Rank 1
Share this question
or