Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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:

HTML
<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:

SQL
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
Posted
Updated 26-Jan-11 15:25pm
v2
Comments
TejuKrishna 27-Jan-11 0:38am    
if you are binding grid in page_load event then bind it in
if(!IspostBack)
{
// Bind grid
}
because before firing any event page_load get fire that's it binding again old values to your grid firstly. and then your update event get raised.
Rohit.Net100 28-Jan-11 9:51am    
i am binding grid on grid_load event
and saving grid on btn_save_click event.
Bound columns data is saving,and i can see values in debug.
But problem is item template(textbox) values are not saving, while debuging it shows me value = "".
Please help

1 solution

Did you put page property IsPostback in your page load to avoid re-binding of the data to datagrid? If not, that would refresh the whole thing and you will not see the value entered.
 
Share this answer
 
Comments
Anupama Roy 27-Jan-11 1:10am    
My Vote of 5!
Rohit.Net100 28-Jan-11 10:19am    
i am binding grid on grid_load event
and saving grid on btn_save_click event.
Bound columns data is saving,and i can see values in debug.
But problem is item template(textbox) values are not saving, while debuging it shows me value = "".
How to avoid grid rebinding on page_load. Can you show me an example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900