hi all..
I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m typing...can sombody plz help me out in this..i need help urgently
I am posting the code in vb.net for the webform as well as html -
Protected Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
-
Dim Stocksent1 As TextBox = CType(e.Item.FindControl("TextBox2"), TextBox)
-
Dim Signed1 As TextBox = CType(e.Item.FindControl("SignedTextBox"), TextBox)
-
Dim Items1 As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
-
Dim myConnection As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
myConnection.Open()
-
-
myCommand1 = New SqlCommand("Update Table3 set Stocksent='" & Stocksent1.Text & "', Signedby='" & Signed1.Text & "' , Flag=0, Sentdate=getdate() where Items='" & Items1 & "' ", myConnection)
-
'myCommand1.Parameters.Add("@Items", SqlDbType.NVarChar).Value = Items
-
'myCommand1.Parameters.Add("@Stocksent1", SqlDbType.NVarChar).Value = Stocksent1.Text
-
'myCommand1.Parameters.Add("@Signedby1", SqlDbType.NVarChar).Value = Signed1.Text
-
ra = myCommand1.ExecuteNonQuery()
-
myConnection.Close()
-
Response.Write("Records Updated")
-
DataGrid1.EditItemIndex = -1
-
DataGrid1.DataBind()
-
DataGrid1.Columns(8).Visible = False
-
DataGrid1.Columns(9).Visible = False
-
DataGrid1.Columns(10).Visible = False
-
DataGrid1.Columns(11).Visible = False
-
DataGrid1.Columns(12).Visible = False
-
-
End Sub
-
HTML CODE -
<form id="Form1" method="post" runat="server">
-
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 296px"
-
runat="server" AutoGenerateColumns="False" DataKeyField="Items" Width="848px" ForeColor="DimGray"
-
BackColor="Wheat" BorderColor="#660033" Height="72px">
-
<HeaderStyle Font-Bold="True" ForeColor="Chocolate" BackColor="LightGray"></HeaderStyle>
-
<Columns>
-
<asp:BoundColumn DataField="Lognumm" ReadOnly="True" HeaderText="Lognumm"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Requestdate" ReadOnly="True" HeaderText="Requestdate"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Hospital" ReadOnly="True" HeaderText="Hospital"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Items" ReadOnly="True" HeaderText="Items"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Currentstock" ReadOnly="True" HeaderText="Currentstock"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Stockrequest" ReadOnly="True" HeaderText="Stockrequest"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Priority" ReadOnly="True" HeaderText="Priority"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Comment" ReadOnly="True" HeaderText="Comment"></asp:BoundColumn>
-
<asp:TemplateColumn Visible="False" HeaderText="Stocksent">
-
<ItemTemplate>
-
<asp:Label id=Label2 runat="server" Text='<%# DataBinder.Eval (Container.DataItem , "Stocksent") %>'>
-
</asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox id=TextBox2 runat="server" Text='<%# DataBinder.Eval(Container.DataItem , "Stocksent") %>'>
-
</asp:TextBox>
-
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Enter value" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
-
</EditItemTemplate>
-
</asp:TemplateColumn>
-
<asp:TemplateColumn Visible="False" HeaderText="Signedby">
-
<ItemTemplate>
-
<asp:Label id=Label1 runat="server" NAME="Label1" Text='<%# DataBinder.Eval(Container, "DataItem.Signedby") %>'>
-
</asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox id=SignedTextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Signedby") %>'>
-
</asp:TextBox>
-
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" Width="128px" ErrorMessage="Enter Value"
-
ControlToValidate="SignedTextBox"></asp:RequiredFieldValidator>
-
</EditItemTemplate>
-
</asp:TemplateColumn>
-
<asp:TemplateColumn Visible="False" HeaderText="Takenby">
-
<ItemTemplate>
-
<asp:Label id="Label3" runat="server"></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
-
<asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Value" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
-
</EditItemTemplate>
-
</asp:TemplateColumn>
-
<asp:TemplateColumn Visible="False" HeaderText="Comments">
-
<ItemTemplate>
-
<asp:Label runat="server"></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox runat="server"></asp:TextBox>
-
</EditItemTemplate>
-
</asp:TemplateColumn>
-
<asp:TemplateColumn HeaderText="Edit">
-
<ItemTemplate>
-
<asp:LinkButton runat="server" CausesValidation="false" CommandName="Edit" Text="Edit" ID="Linkbutton1"></asp:LinkButton>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:LinkButton runat="server" CommandName="Update" Text="Update" ID="Linkbutton2"></asp:LinkButton>
-
<asp:LinkButton runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel" ID="Linkbutton3"></asp:LinkButton>
-
</EditItemTemplate>
-
</asp:TemplateColumn>
-
</Columns>
-
</asp:datagrid>
23 1926 Frinavale 9,735
Recognized Expert Moderator Expert
hi all..
I am trying to update my datagrid in my webform...but its not getting updated..though in the database it removing the <null> and inserting a blank field....its not taking the input which m typing...can sombody plz help me out in this..i need help urgently
I am posting the code in vb.net for the webform as well as html...
Hi Tanya,
In the future could you please post your code within [code] tags.
(For example you'd type [code=vbnet]'...paste code here...[ /code] if you wanted to post vb.net code)
This just makes it easier for everyone.
Are you by any chance binding your DataGrid to its DataSource during PageLoad?
Hi Tanya,
In the future could you please post your code within [code] tags.
(For example you'd type [code=vbnet]'...paste code here...[ /code] if you wanted to post vb.net code)
This just makes it easier for everyone.
Are you by any chance binding your DataGrid to its DataSource during PageLoad?
yes i am do u want me to give u the code for page load event as well?
mzmishra 390
Recognized Expert Contributor
I think this part is missing in your code
DataGrid.DataSo urce
I think this part is missing in your code
DataGrid.DataSo urce
where shud this part be i mean Datagrid.Dataso urce????
Frinavale 9,735
Recognized Expert Moderator Expert
where shud this part be i mean Datagrid.Dataso urce????
Could you please post your code for the PageLoad method?
Could you please post your code for the PageLoad method?
-
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Dim cn As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
Dim da As New SqlDataAdapter("select * from Table3 where Lognumm= '" & Request.QueryString("ID") & "' and Flag=1", cn)
-
Dim dt As New DataTable
-
da.Fill(dt)
-
da.Dispose()
-
cn.Dispose()
-
Me.DataGrid1.DataSource = dt
-
Me.DataGrid1.DataBind()
-
End Sub
-
-
Frinavale 9,735
Recognized Expert Moderator Expert -
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Dim cn As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
Dim da As New SqlDataAdapter("select * from Table3 where Lognumm= '" & Request.QueryString("ID") & "' and Flag=1", cn)
-
Dim dt As New DataTable
-
da.Fill(dt)
-
da.Dispose()
-
cn.Dispose()
-
Me.DataGrid1.DataSource = dt
-
Me.DataGrid1.DataBind()
-
End Sub
-
-
Try changing your code so that you only set and bind the DataSource to your DataGrid when it is not isPostBack
Eg -
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
-
If IsPostBack = False Then
-
-
Dim cn As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
Dim da As New SqlDataAdapter("select * from Table3 where Lognumm= '" & Request.QueryString("ID") & "' and Flag=1", cn)
-
Dim dt As New DataTable
-
da.Fill(dt)
-
da.Dispose()
-
cn.Dispose()
-
Me.DataGrid1.DataSource = dt
-
Me.DataGrid1.DataBind()
-
-
End If
-
End Sub
-
The reason for this is during your page cycle, when you're in the PageLoad, you can set your control's properties Before ASP.NET sets them. If you do this, then any properties that the control gathered from the user is lost....so if your user is editing an empty row and adding new values to it...and then you reset the data source for your DataGrid in PageLoad, you will lose the data that the user supplied while editing.
(PS. Please take a look at my not on using the [code] tags again. It should be code=vbnet not code : Vb.Net :) Thanks)
lol....hi
well i did write it the way u said as shown below but when i click the edit link its just showing me a blank page the datagrid disappears...th e entire code for the page is shown below( i hope i m right this time :-)) -
-
Imports System.Data.SqlClient
-
Public Class trial
-
Inherits System.Web.UI.Page
-
Dim myCommand1 As New SqlCommand
-
Protected WithEvents LinkButton4 As System.Web.UI.WebControls.LinkButton
-
Protected WithEvents LinkButton5 As System.Web.UI.WebControls.LinkButton
-
Dim ra As Integer
-
-
#Region " Web Form Designer Generated Code "
-
-
'This call is required by the Web Form Designer.
-
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
-
End Sub
-
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
-
-
'NOTE: The following placeholder declaration is required by the Web Form Designer.
-
'Do not delete or move it.
-
Private designerPlaceholderDeclaration As System.Object
-
-
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
-
'CODEGEN: This method call is required by the Web Form Designer
-
'Do not modify it using the code editor.
-
InitializeComponent()
-
End Sub
-
-
#End Region
-
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
If IsPostBack = False Then
-
-
-
Dim cn As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
Dim da As New SqlDataAdapter("select * from Table3 where Lognumm= '" & Request.QueryString("ID") & "' and Flag=1", cn)
-
Dim dt As New DataTable
-
da.Fill(dt)
-
da.Dispose()
-
cn.Dispose()
-
Me.DataGrid1.DataSource = dt
-
Me.DataGrid1.DataBind()
-
end if
-
End Sub
-
-
Protected Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
-
DataGrid1.Columns(8).Visible = True
-
DataGrid1.Columns(9).Visible = True
-
DataGrid1.Columns(10).Visible = True
-
DataGrid1.Columns(11).Visible = True
-
-
DataGrid1.EditItemIndex = e.Item.ItemIndex
-
DataGrid1.DataBind()
-
-
End Sub
-
Protected Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
-
-
Dim Stocksent1 As TextBox = CType(e.Item.FindControl("TextBox2"), TextBox)
-
Dim Signed1 As TextBox = CType(e.Item.FindControl("SignedTextBox"), TextBox)
-
Dim Items1 As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
-
Dim myConnection As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
myConnection.Open()
-
-
myCommand1 = New SqlCommand("Update Table3 set Stocksent='" & Stocksent1.Text & "', Signedby='" & Signed1.Text & "' , Flag=0, Sentdate=getdate() where Items='" & Items1 & "' ", myConnection)
-
'myCommand1.Parameters.Add("@Items", SqlDbType.NVarChar).Value = Items
-
'myCommand1.Parameters.Add("@Stocksent1", SqlDbType.NVarChar).Value = Stocksent1.Text
-
'myCommand1.Parameters.Add("@Signedby1", SqlDbType.NVarChar).Value = Signed1.Text
-
ra = myCommand1.ExecuteNonQuery()
-
myConnection.Close()
-
Response.Write("Records Updated")
-
DataGrid1.EditItemIndex = -1
-
DataGrid1.DataBind()
-
DataGrid1.Columns(8).Visible = False
-
DataGrid1.Columns(9).Visible = False
-
DataGrid1.Columns(10).Visible = False
-
DataGrid1.Columns(11).Visible = False
-
DataGrid1.Columns(12).Visible = False
-
-
End Sub
-
Private Sub LinkButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton5.Click
-
-
Response.Redirect("http://localhost/WebApplication3\Warehouse1.aspx")
-
-
End Sub
-
Private Sub LinkButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton4.Click
-
-
Response.Redirect("http://localhost/WebApplication3\WebForm6.aspx")
-
-
End Sub
-
-
End Class
-
Try changing your code so that you only set and bind the DataSource to your DataGrid when it is not isPostBack
Eg -
-
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
-
If IsPostBack = False Then
-
-
Dim cn As New SqlConnection("Server=SERVER;uid=sa;pwd=;Database=Central")
-
Dim da As New SqlDataAdapter("select * from Table3 where Lognumm= '" & Request.QueryString("ID") & "' and Flag=1", cn)
-
Dim dt As New DataTable
-
da.Fill(dt)
-
da.Dispose()
-
cn.Dispose()
-
Me.DataGrid1.DataSource = dt
-
Me.DataGrid1.DataBind()
-
-
End If
-
End Sub
-
The reason for this is during your page cycle, when you're in the PageLoad, you can set your control's properties Before ASP.NET sets them. If you do this, then any properties that the control gathered from the user is lost....so if your user is editing an empty row and adding new values to it...and then you reset the data source for your DataGrid in PageLoad, you will lose the data that the user supplied while editing.
(PS. Please take a look at my not on using the [code] tags again. It should be code=vbnet not code : Vb.Net :) Thanks)
hi i did it but its like showing me a blank page wehn i click edit...y is it so???
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brett Hargreaves |
last post by:
I'm having a major problems with Datagrid and the update command.
Basically when I enter into edit mode in my data grid then set a new value,
the update command is not picking up the new value.
So, if the original value is 10, and I change it to 20 the txtFieldName.Text
field still thinks it has the old value of 10 in it.
Anyone any ideas...
|
by: Tomas Vera |
last post by:
Hello All,
I'm having problems creating a page with dynamic checkboxes in a WebApp.
In my app, I need to query a database, then (based on results) add
checkboxes to my form and set their "Checked" state. Since the controls are
dynamically created, I'm using the OnInit event to create the checkboxes
and set the "Checked" state from the DB.
...
|
by: Jim McDermott |
last post by:
A client I provide lan support to posed a web app question I'm not qualified
to
answer....
They build OEM mechanisms to order from an assortment of stock parts - I
know this is a stretch, but kind of like autos. You pick a base model, then
make a engine selection, then select color, etc. Of course, each subsequent
choice is predicated on...
|
by: Martin |
last post by:
I am a .Net newbie. I have Visual Studio.Net 2003 and have the luxury
of being able to do some R&D/learning in a non-production environment.
I want to develop a web application that will get the data that it
serves out from two sources: (1) a database (probably MS Access but
could be SQL Server) and (2) directly from another application...
|
by: mjc9885 |
last post by:
Hope someone can help me out with this. I made some minor
modifications to some underlying VB code for a web app -- no changes to
any .aspx pages were required. I then deployed the changes to a test
environment and everything worked fine. I used XCopy method to do this
-- Copied the project to a localhost directory, then copied the dll's...
| |
by: terryc |
last post by:
Hi Guys
I've set up a web app on my machine using IIS and XP Pro. I can access the site using my machine (http://localhost/appName) no problems, but when I try and access this app using another machine over the network (http://192.XXX.X.X/appName) it just times out.
Any ideas what the problem would be?
I've just changed machine, previous...
|
by: Andrew Robinson |
last post by:
I am working on a system system that requires optimistic concurrency within
a web app. At first I thought this would be easy. We generate our own
entities and dal/service layer but I now see that working with controls like
a grid view pose some very complicated issues.
If I am using rowversion, when do I start the "clock"? When I first...
|
by: tanya2001 |
last post by:
hi m bac 2 trouble u agn
can u tell me how do i update a datagrid which has got a datagrid which is displayed on a button click and thn it tht datagrid thr's a link which has 2 be updated...wen m clicking edit on the datagrid nothing is returning back...what shud i give in the page post back event?i cant give d code for datagrid coz tht shud b...
|
by: CMoya |
last post by:
Can anyone point to an article or blog that describes the *functional*
differences between a "Web Application" and a "Web Site" in VS2008....
caveats, gotchas? I'm aware of the compile differences as it was in VS2005
(one dll, vs multiple), but is there anything else to keep in mind? Like
some things that might work in one but not the other?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |