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

No Value for GridDataItem

4 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikhail
Top achievements
Rank 1
Mikhail asked on 12 May 2008, 05:36 PM
Hello
I have a grid set up like so:

<radG:RadGrid ID="RadGrid1"  runat="server"  Skin="UCITGrid" AllowPaging="True"  AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableAJAX="True" GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnItemCommand="RadGrid1_OnItemCommand" PageSize="20">

<MasterTableView DataSourceID="SqlDataSource1" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordImageUrl="../../RadControls/Grid/Skins/UCITGrid/AddRecord.png" EditMode="InPlace">

<CommandItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible="true"><img style="border:0px" alt="" src="../../RadControls/Grid/Skins/UCITGrid/AddRecord.png" /> Add a New Program</asp:LinkButton>
</CommandItemTemplate>

<SortExpressions>
<radG:GridSortExpression FieldName="fldArchive" SortOrder="Ascending" />
</SortExpressions>

<Columns>

<radG:GridBoundColumn DataField="fldID" UniqueName="IDColumn" Display="False">
</radG:GridBoundColumn>

<radG:GridBoundColumn DataField="fldName" HeaderText="Name" UniqueName="NameColumn">
<ItemStyle width="70%"/>
</radG:GridBoundColumn>

<radG:GridCheckBoxColumn DataField="fldArchive" HeaderText="Archive" UniqueName="ArchiveColumn">
<ItemStyle width="15%"/>
</radG:GridCheckBoxColumn>

<radG:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="../../RadControls/Grid/Skins/UCITGrid/Update3.png"  EditImageUrl="../../RadControls/Grid/Skins/UCITGrid/Edit2.png"  CancelImageUrl="../../RadControls/Grid/Skins/UCITGrid/Cancel3.png" InsertImageUrl="../../RadControls/Grid/Skins/UCITGrid/Update3.png" InsertText="Save" HeaderText="Options" UniqueName="EditCommandColumn">
<ItemStyle width="15%"/>
</radG:GridEditCommandColumn>
</Columns>

</MasterTableView>

</
radG:RadGrid>

I have this in my code behind:

Protected Sub RadGrid1_OnItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
    
If e.CommandName = "Update" Then
        
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
        
Dim name As String = dataItem("NameColumn").Text
        Response.Write(name)
    
End If
End Sub

For some reason, the name string contains an empty string, when in reality, there is a value assigned to it. Is there something here that I'm missing?

Please let me know. Thank you!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 May 2008, 06:20 AM
Hi Mikhail,

Try accessing the edited value on clicking the update button as shown below.

CS:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if ((e.CommandName == "Update") && (e.Item is GridEditableItem))  
        {  
            GridEditableItem editeditem = (GridEditableItem)e.Item;  
            string name = editeditem["NameColumn"].Text.ToString();  
        }  
   } 


Thanks
Princy.
0
Mikhail
Top achievements
Rank 1
answered on 13 May 2008, 03:21 PM
Princy,
Thanks for the reply. I tried exactly doing what you did but still I can't get the name value, it's still an empty string.

    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs)  
        If ((e.CommandName = "Update"AndAlso (TypeOf e.Item Is GridEditableItem)) Then 
            Dim editeditem As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim name As String = editeditem("NameColumn").Text.ToString  
            Response.Write(name)  
        End If 
    End Sub 
0
Accepted
Shinu
Top achievements
Rank 2
answered on 14 May 2008, 07:01 AM
Hi Mikhail,

Give a try with the following code snippet and see whether you are able to access the Edited text.

CS:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)   
    {   
        if ((e.CommandName == "Update") && (e.Item is GridEditableItem))   
        {   
            GridEditableItem editeditem = (GridEditableItem)e.Item;   
           string name= (editedItem["NameColumn"].Controls[0] as TextBox).Text; 
 
        }   
   }  
 
   


Thanks
Shinu.
0
Mikhail
Top achievements
Rank 1
answered on 14 May 2008, 03:04 PM
Shinu Thanks a lot, that worked!
Tags
Grid
Asked by
Mikhail
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mikhail
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or