“项目模板"列中的文本框未保存数据
问题描述:
我正在保存网格数据.网格在项目模板列中包含一个文本框.但是它没有保存任何数据,而是在文本框中输入的(仅保存"NULL").调试时没有错误.
任何帮助表示赞赏.以下是我正在使用的代码.
VB代码:
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代码:
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" />
存储的Proc:
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
答
您是否在页面加载中添加了页面属性IsPostback
以避免将数据重新绑定到datagrid?如果没有,那将刷新整个内容,并且您将看不到输入的值.
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.