Hello, I'm new to ASP.NET.
I'm requesting help. I've tried hard but with no result.
I want to provide my user a Gridview filled with data from database, allowing him to edit these records not in order to update the database, but in order to insert edited rows in db as new records through a stored procedure.
So I have my Gridview with DataSource set to a DataTable on page Load event
:
gvAutorizzazioni.DataSourceID = ""
gvAutorizzazioni.DataSource = ds.Tables(0)
with textboxes and ddlists. I put them in ItemTemplate (not in EditItemTemplate) and added a CommandField:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkCreaAutorizz" runat="server" CommandName="CreaAutorizz" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
>Crea autorizzazione</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
In the Click event of the button I want to retrieve current values of the controls, as displayed on Web page after user's actions, and pass them to my sp as a comma-separated string.
The problem is: when I retrieve data using GridView.FindControl, I only get unedited values, those initially displayed from database, not the actual values displayed on screen.
Protected Sub gvAutorizzazioni_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvAutorizzazioni.RowCommand
If (e.CommandName = "CreaAutorizz") Then
Dim strPerInsert As String = ""
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvAutorizzazioni.Rows(index)
Dim strAdd As String = ""
strAdd = (CType(row.FindControl("ddlStrutture"), DropDownList).SelectedItem.Value)
If String.IsNullOrEmpty(strAdd) = False Then strPerInsert = strPerInsert & strAdd & ","
'...and so on to add values to string
What to do to retrieve edited values? Thank you for any help!
(I wanted to avoid - if it's possible! - to use Edit built-in capabilities (Edit button, EditItemTemplate etc.) because I don't need to make any real updating and I don't have a clear idea of how to "bypass" the parts I don't want.)
Cri