i used Grid view and here is the code i wrote: -
Protected Sub ButtonAddFile_Click(ByVal sender As Object, ByVal e As EventArgs)
-
Dim gv As New GridView
-
gv.Style.Add("position", "absolute")
-
gv.Style.Add("left", "575px")
-
gv.Style.Add("top", "220px")
-
gv.EnableViewState = False
-
form1.Controls.Add(gv)
-
gv.DataSource = GetDataTable()
-
gv.DataBind()
-
Dim lbl As New Label
-
lbl.Style.Add("position", "absolute")
-
lbl.Style.Add("left", "575px")
-
lbl.Style.Add("top", "20px")
-
End Sub
-
Private Function GetDataTable() As DataTable
-
Dim doc As New DataTable("Document")
-
Dim id As New DataColumn("Document")
-
-
id.DataType = GetType(String)
-
id.Unique = True
-
id.AllowDBNull = False
-
id.Caption = "Document"
-
-
doc.Columns.Add(id)
-
-
Dim filing As New DataColumn("Type")
-
filing.DataType = GetType(String)
-
'filing.MaxLength = 35
-
filing.AllowDBNull = False
-
-
doc.Columns.Add(filing)
-
doc.PrimaryKey = New DataColumn() {id}
-
'add data to data table
-
-
Dim newdoc As DataRow = doc.NewRow()
-
newdoc("Document") = FileToUpload.PostedFile.FileName
-
newdoc("Type") = listDocType.SelectedValue
-
-
doc.Rows.Add(newdoc)
-
Return doc
-
End Function
-
1. But it adds only one row everytime i click the AddFile button and overrides the previous row, it doesnt add on after another, whats going wrong here?
2. Also If I have to add a delete button of GridView , what code should i write so that it deletes that particular row every time i click delete
5 1699 Frinavale 9,735
Recognized Expert Moderator Expert
Hi Sspost,
I have moved your question to the .NET Forums section. The .NET Articles section is reserved for "how-tos" and other informational articles and is not meant for your questions. You will receive help with your problems in the .NET Forums section so please post any further questions here (Blue menu: Forums->.NET)
Thanks,
-Moderator
Plater 7,872
Recognized Expert Expert
You need to be adding your rows to your dataobject, everytime you change the datasource property it wipes out all your old values and re-creates from the new ones.
Maintain a DataTable object and add rows to that.
[Ok , I used dataobject and can add rows one after another, but i added delete button but still cant get the delete to delete the rows from gridview ...here is the code i wrote: -
<asp:datagrid id="DataGrid1" runat="server" Width="100%" AutoGenerateColumns="False">
-
<AlternatingItemStyle BackColor="beige"></AlternatingItemStyle>
-
<ItemStyle Font-Size="Smaller" HorizontalAlign="Center" BackColor="LightGray"></ItemStyle>
-
<HeaderStyle Font-Size="Smaller" Font-Bold="True" HorizontalAlign="Center" ForeColor="White"
-
BackColor="DimGray"></HeaderStyle>
-
<Columns>
-
<asp:BoundColumn DataField="Document" HeaderText="Document"></asp:BoundColumn>
-
<asp:BoundColumn DataField="Document Title" HeaderText="Document Title"></asp:BoundColumn>
-
<asp:ButtonColumn commandname="Delete" headertext="Delete" Text="Delete"></asp:ButtonColumn>
-
</Columns>
-
</asp:datagrid>
-
here is the code: -
Protected Sub ButtonDeleteFile_Click(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
-
If Not e.CommandName <> "Delete" Then
-
Return
-
-
Dim sessionObject As Object = Session("docDataTable")
-
-
If Not (sessionObject Is Nothing) Then
-
Dim idValue As String = e.Item.Cells(0).Text
-
-
Dim doc As DataTable = CType(sessionObject, DataTable)
-
Dim sqlFilter As String = "Document = '" + idValue + "'"
-
Dim filteredArray As DataRow() = doc.Select(sqlFilter)
-
If filteredArray.Length > 0 Then
-
Dim filteredRow As DataRow = filteredArray(0)
-
doc.Rows.Remove(filteredRow)
-
End If
-
End If
-
End If
-
-
End Sub
-
But this doesnt even get to the if stmt and i dont know why VisualStudio is says "unused local variable" for each and every varaible used here.
Plater 7,872
Recognized Expert Expert
Do you have more then one function handling that event?
No I dont
Now I am getting this :
at the following line:
doc.Rows.Remove (filteredRow)
it gives me exception: System.IndexOut OfRangeExceptio n - The given DataRow is not in the current DataRowCollecti on. , even though the search row is the primary key one........does anyone has any idea why its giving it? even though the comparing row is the correct one.....
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: pmud |
last post by:
Hi,
I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:
1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?
|
by: pmud |
last post by:
Hi,
I am using teh following code for sorting the data grid but it doesnt work.
I have set the auto generate columns to false. & set the sort expression for
each field as the anme of that field... This grid displayes results based on
users search..
public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
|
by: Filippo Pandiani |
last post by:
I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?
Thanks,
Filippo.
|
by: pmud |
last post by:
Hi,
I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:
1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?
|
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: 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: 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...
|
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...
|
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: 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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |