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

Textbox inside Item Template Column not saving data

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rohit
Top achievements
Rank 1
rohit asked on 27 Jan 2011, 03:18 AM
I am saving grid data. Grid contains one textbox in item template column. But it was not saving any data, which was entered in textbox(Just saving 'NULL'). There was not error while debugging.
Any help is appreciated. Below is code i am using.
VB Code:
Public Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
AddG()
End Sub
Public Sub AddG()
        For Each item As GridDataItem In GD_Prod.Items
Dim tx3 As TextBox = DirectCast(item("PL_STUDENT_Portions_Planned").FindControl("TxtSTUPort"), TextBox)
 Dim str3 As Object = tx3.text
            If tx3.Text = Nothing Then
                str3 = DBNull.Value
            ElseIf IsNumeric(tx3.Text) Then
                str3 = Val(tx3.Text)
            End If
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("FConnectionString").ConnectionString)
            Dim cmd As New SqlCommand("P_FN_PR_InsertGridData", con)
            cmd.CommandType = CommandType.StoredProcedure
 cmd.Parameters.Add("@PL_Student_Portions_Planned", System.Data.SqlDbType.VarChar)
            cmd.Parameters("@PL_Student_Portions_Planned").Value = str3
con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
Next
    End Sub

ASPX Code:

<telerik:RadGrid ID="GD_Prod" runat="server" AllowPaging="True" ShowHeader="False"
                    AutoGenerateColumns="False" GridLines="None" Height="173px" Skin="Outlook" 
                    Width="1107px" PageSize="1">
                      <MasterTableView>
                              <Columns>
<telerik:GridTemplateColumn UniqueName="PL_STUDENT_Portions_Planned" 
                               >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtSTUPort"   runat="server" Height="16px"
                                        Width="30px" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                        ControlToValidate="TxtSTUPort" ErrorMessage="*" ForeColor="#CC3300" 
                                        SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                        ControlToValidate="TxtSTUPort" ErrorMessage="Number" ForeColor="#CC3300" 
                                        SetFocusOnError="True" ValidationExpression="[0-9]*" Display="Dynamic" 
                                        Font-Size="6px"></asp:RegularExpressionValidator>
                                </ItemTemplate>
                                <HeaderStyle Width="19px" />
                            </telerik:GridTemplateColumn>
 </Columns>
                        
                </telerik:RadGrid>
<asp:Button ID="btnsave" runat="server" Height="20px" Text="SAVE" Width="50px"
                        ToolTip="Click to Save " BackColor="#DFEFFF" ForeColor="#003399" />

Stored Proc:
ALTER PROCEDURE [DBO].P_FN_PR_InsertGridData
      (
@PL_Student_Portions_Planned varchar(10) = 0
)
AS
begin
INSERT INTO FNProdRecDetails (PL_Student_Portions_Planned)
values(@PL_Student_Portions_Planned)
End
Return

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 01 Feb 2011, 10:45 AM
Hello rohit,

Have you tried debugging to see what is the value of str3 while it goes through the if-statement that decides whether it will be evaluated as null or a value? Unless the textbox does not carry the value in the button click event, the problem is not related to RadGrid's functionality.

Additionally, as you are manually adding the record (not on insert command) you would need to rebind your RadGrid in order for it to display the inserted item.

Kind regards,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
rohit
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or