Microsoft
Software
Hardware
Network
Question : ASP.Net: I need help, trying to pass a gridview selected row ID to a procedure.
Title:
Asp.Net Have trouble passing a row.Cells(1).Text, value into my insert statement
For instantance this line works: if I hard code the ID value '23' into the below line:
<?xml:namespace prefix = asp /><asp:SqlDataSource id=UploadPictureDataSource
" runat="server">
InsertCommand="INSERT INTO [CustomerImages] ([ImageID],[EquipmentID], [Title], [ImageData], MIMEType)
VALUES (@ImageId, (SELECT [EquipmentID] FROM Equipment WHERE ID = '23'), @Title, @ImageData, @MIMEType)" >
</asp:SqlDataSource>
The below SUb gets the row ID value: on what ever row I've selected
Sub GridView2_SelectedIndexCha
nged(ByVal
sender As Object, ByVal e As EventArgs)
' Get the currently selected row using the SelectedRow property.
Dim row As GridViewRow = GridView2.SelectedRow
MessageLabel.Text = "You selected row ID = " & row.Cells(1).Text & "."
End Sub
this message label prints out the select row ID:
<asp:label id="MessageLabel" forecolor="Red" runat="server"/>
You selected row ID = 23
--------------------------
----------
----------
I have tried both of the below coding and they both fails:
--------------------------
----------
----------
----------
----------
---
this method Fails:
<asp:SqlDataSource id=UploadPictureDataSource
" runat="server">
InsertCommand="INSERT INTO [CustomerImages] ([ImageID],[EquipmentID], [Title], [ImageData], MIMEType)
VALUES (@ImageId, (SELECT [EquipmentID] FROM Equipment WHERE ID = '" + row.Cells(1).Text + "'), @Title, @ImageData, @MIMEType)" ></asp:SqlDataSource></asp
:SqlDataSo
urce>
this line also fails:
<asp:SqlDataSource
" runat="server"><asp:SqlDat
aSource
" runat="server">InsertComma
nd="INSERT
INTO [CustomerImages] ([ImageID],[EquipmentID], [Title], [ImageData], MIMEType)
VALUES (@ImageId, (SELECT [EquipmentID] FROM Equipment WHERE ID = " + row.Cells(1).Text + "), @Title, @ImageData, @MIMEType)" ></asp:SqlDataSource></asp
:SqlDataSo
urce>
--------------------------
----
Answer : ASP.Net: I need help, trying to pass a gridview selected row ID to a procedure.
Have a look at this article:
http://msdn.microsoft.com/
en-us/libr
ary/
system
.web.ui.we
bcontrols.
sqldatasou
rce.update
.aspx
Hope it helps you.
Random Solutions
Spanning-tree Cost to block uplink to core Switches.
Reset of displayed form when "requery" is performed
Constant BSOD on boot/install of Windows 7
Dynamically Change .XSD File Location in Crystal Reports Using ASP.NET 2.0
Static route to website in Squid
'guid' is null or not an object in Jquery
In .NET, how can I add to a variable value to a query result using LINQ to SQL?
error while installing Exchang 2010
Having a problem seeing USB devices after installing libusb - NO KEYBOARD OR MOUSE !!
Can't print to Dymo Labelwriter 400 turbo after adding labelwriter 450 turbo drivers on windows 2003 terminal server