Hello,
I am attempting to to take edited values from a datagrid control and update
the underlying database. Problem is that some of the edited values don quite
seem to make it to my update sub. My code is shown below. The values that
are not appearing are Cell(4) - sCompletion and Cell(5) - sNote. The other
values show up just fine.
What am I missing here?
Bernard
Dim iLogID As String = Convert.ToStrin g(e.Item.Cells( 0).Text)
Dim sEntry As String = CType(e.Item.Ce lls(2).Controls (0), TextBox).Text
Dim sResp As String = CType(e.Item.Ce lls(3).Controls (1),
DropDownList).S electedItem.Val ue
Dim sCompletion As String = CType(e.Item.Ce lls(4).Controls (0), TextBox).Text
'Now.Date.ToStr ing
Dim sNote As String = CType(e.Item.Ce lls(5).Controls (0), TextBox).Text
If sNote = "" Then sNote = "*"
'Fill a string builder just to check values passed by DataGrid
Dim sb = New StringBuilder
sb.Append("LogI tem = " & iLogID)
sb.Append("; EntryDate: " & sEntry)
sb.Append("; Responsible: " & sResp)
sb.Append("; Completion Date: " & sCompletion)
sb.Append("; Note: " & sNote)
Label1.Text = sb.ToString
=============== =============== =============== =============== =============== =====
The DataGrid Code
=============== =============== =============== =============== =============== =====
<asp:datagrid id="DataGrid1" runat="server" ForeColor="Blac k"
BorderColor="#9 99999" BorderStyle="No ne"
BorderWidth="1p x" BackColor="Whit e" CellPadding="3"
GridLines="Vert ical" AutoGenerateCol umns="False">
<FooterStyle BackColor="#CCC CCC"></FooterStyle>
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#000 099"></SelectedItemSty le>
<AlternatingIte mStyle BackColor="#CCC CCC"></AlternatingItem Style>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="Blac k"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="LogI D" ReadOnly="True"
HeaderText="Log ID"></asp:BoundColumn >
<asp:BoundColum n DataField="LogI tem" ReadOnly="True"
HeaderText="Log Item"></asp:BoundColumn >
<asp:BoundColum n DataField="LogD ate" HeaderText="Ent ry"
DataFormatStrin g="{0:MM-dd-yy}"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Res p">
<ItemTemplate >
<asp:Label runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.UserN ame") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st id="UserIDList " runat="server" Datasource="<%#
GetUserIDList() %>" DataTextField=" UserName" DataValueField= "UserID" />
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="Comp letionDate" HeaderText="Com pleted"
DataFormatStrin g="{0:MM-dd-yy}"></asp:BoundColumn >
<asp:BoundColum n DataField="LogI temNote"
HeaderText="Not e"></asp:BoundColumn >
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate"
CancelText="Can cel" EditText="Edit" ></asp:EditCommand Column>
<asp:ButtonColu mn Text="Delete"
CommandName="De lete"></asp:ButtonColum n>
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="Blac k"
BackColor="#999 999"></PagerStyle>
</asp:datagrid> 1 1726
Found it thanks to Scott Mitchell's book: "Asp.Net Data Web Controls Kick
Start."
Needed to assign OnEdi/Cancel/Update/Delete commands for the grid. Also
added postback check in page load event. If the page is posted back, fill
the grid. If not, do the update.
If Not IsPostBack() Then
FillGrid()
End If
Thanks Scott!
PS - Great Book!
Bernard
"BW" <bw*********@ae gisadvisers.com > wrote in message
news:OP******** ******@TK2MSFTN GP10.phx.gbl... Hello,
I am attempting to to take edited values from a datagrid control and update the underlying database. Problem is that some of the edited values don quite seem to make it to my update sub. My code is shown below. The values that are not appearing are Cell(4) - sCompletion and Cell(5) - sNote. The other values show up just fine.
What am I missing here?
Bernard
Dim iLogID As String = Convert.ToStrin g(e.Item.Cells( 0).Text)
Dim sEntry As String = CType(e.Item.Ce lls(2).Controls (0), TextBox).Text
Dim sResp As String = CType(e.Item.Ce lls(3).Controls (1), DropDownList).S electedItem.Val ue
Dim sCompletion As String = CType(e.Item.Ce lls(4).Controls (0), TextBox).Text 'Now.Date.ToStr ing
Dim sNote As String = CType(e.Item.Ce lls(5).Controls (0), TextBox).Text
If sNote = "" Then sNote = "*"
'Fill a string builder just to check values passed by DataGrid
Dim sb = New StringBuilder
sb.Append("LogI tem = " & iLogID)
sb.Append("; EntryDate: " & sEntry)
sb.Append("; Responsible: " & sResp)
sb.Append("; Completion Date: " & sCompletion)
sb.Append("; Note: " & sNote)
Label1.Text = sb.ToString
=============== =============== =============== =============== =============== =====
The DataGrid Code
=============== =============== =============== =============== =============== =====
<asp:datagrid id="DataGrid1" runat="server" ForeColor="Blac k" BorderColor="#9 99999" BorderStyle="No ne" BorderWidth="1p x" BackColor="Whit e" CellPadding="3" GridLines="Vert ical" AutoGenerateCol umns="False"> <FooterStyle BackColor="#CCC CCC"></FooterStyle> <SelectedItemSt yle Font-Bold="True" ForeColor="Whit e" BackColor="#000 099"></SelectedItemSty le> <AlternatingIte mStyle BackColor="#CCC CCC"></AlternatingItem Style> <HeaderStyle Font-Bold="True" ForeColor="Whit e" BackColor="Blac k"></HeaderStyle> <Columns> <asp:BoundColum n DataField="LogI D" ReadOnly="True" HeaderText="Log ID"></asp:BoundColumn > <asp:BoundColum n DataField="LogI tem" ReadOnly="True" HeaderText="Log Item"></asp:BoundColumn > <asp:BoundColum n DataField="LogD ate" HeaderText="Ent ry" DataFormatStrin g="{0:MM-dd-yy}"></asp:BoundColumn > <asp:TemplateCo lumn HeaderText="Res p"> <ItemTemplate > <asp:Label runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.UserN ame") %>'> </asp:Label> </ItemTemplate> <EditItemTempla te> <asp:DropDownLi st id="UserIDList " runat="server" Datasource="<%# GetUserIDList() %>" DataTextField=" UserName" DataValueField= "UserID" /> </EditItemTemplat e> </asp:TemplateCol umn> <asp:BoundColum n DataField="Comp letionDate" HeaderText="Com pleted" DataFormatStrin g="{0:MM-dd-yy}"></asp:BoundColumn > <asp:BoundColum n DataField="LogI temNote" HeaderText="Not e"></asp:BoundColumn > <asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate" CancelText="Can cel" EditText="Edit" ></asp:EditCommand Column> <asp:ButtonColu mn Text="Delete" CommandName="De lete"></asp:ButtonColum n> </Columns> <PagerStyle HorizontalAlign ="Center" ForeColor="Blac k" BackColor="#999 999"></PagerStyle> </asp:datagrid> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: NETDeveloper |
last post by:
Hi,
I almost have my nested datagrid working properly. I created a datagrid on a
user control and dropped that onto another datagrid. At first, I noticed when
I was stepping through the code, that the update linkbutton actually goes to
the edit command instead of the update command (which I'm pretty sure would
be a bug). Anyway, I took out the editcommmand column and replaced it with a
regular template column. Within the...
|
by: Brett Hargreaves |
last post by:
I'm having 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 why!!!
|
by: abdoly |
last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update
that is the code
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
TextBox temp
temp=(TextBox)e.Item.Cells.Controls
String str=temp.Text;
str always returnt the old value of the cell (before being updated)
would u plz tell me about whats wrong i m doin
|
by: siaj |
last post by:
Helo All,
If some one has faced a similar issue..
My datagrid Update command is not getting fired in fact it seems that the no
event fires on clicking the update link. Although the cancel and the Edit
Commmand are getting fired properly.
The One difference I have seen is that in the task bar ..on hovering on the
link the javascript for the update link seems different. I dont know if it
makes sense..
|
by: siaj |
last post by:
Hello All,
If some one has faced a similar issue..
My datagrid Update command is not getting fired in fact it seems that the no
event fires on clicking the update link. Although the cancel and the Edit
Commmand are getting fired properly.
The One difference I have seen is that in the task bar ..on hovering on the
link the javascript for the update link seems different. I dont know if it
makes sense..
| |
by: Geraldine Hobley |
last post by:
Hello I'm getting the above mentioned error in my applicatio
I have a datagrid bound to a datasource like s
MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine
However I have another field on the form which is a richtextbox and is bound to another field in the same datasourc
like s
Me.RtxtDialog.DataBindings.Add("text", MyDataset.Tables.Item("Orders"), "MyRichTextField") - this field accepts nulls in the databas
|
by: William LaMartin |
last post by:
In the past, I have filled a datagrid with data from an Access database
table using a data adapter and dataset, where I used the OleDbCommandBuilder
to have the program create the insert, delete and update commands
automatically for the dataadapter. I think those database tables had no
more than 10 or 12 fields. Then to save the changes in the datagrid to the
database, I simply evoked the dataadapter update command. No problems.
...
|
by: logdenav |
last post by:
I have a datagrid with a datatable for the datasource
A thread update the datatable (acceptchanges) in the ui thread (Invoke
or BeginInvoke)
the datagrid makes changes but with a lot of data it's difficult to fix
the location of the scrollbars.
Thanks
Bruno
|
by: thebison |
last post by:
Hi all,
I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.
My problem is to do with a DataGrid. I have successfully coded the
DataGrid so that you can Edit, Update, Cancel. However as my Update
Stored Procedure only updates certain columns I would like to make
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |