[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to get values from a gridview control and pass them to a update parameters ?

Posted on 2009-07-06
11
Medium Priority
?
813 Views
Last Modified: 2012-05-07
HI

Things are like this:
1. I have a gridview and objectdatasource controls.
2. The objectdatasource must get some update parameters in order to give them to the BLL

Those parameters have to get the values from a couple of controls in the gridview that are enclosed in EditItemTemplate tags.

How to that?

Thanks in advace.
0
Comment
Question by:dimensionav
11 Comments
 
LVL 8

Expert Comment

by:MrAgile
ID: 24790244
Hi There,

Without seeing any of your code. You may be able to do this using the (RowCommand event).

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx
0
 
LVL 2

Expert Comment

by:nathanbaker
ID: 24790853

There are few ways of doing it, depending on the event you use...
 here are a few examples...

protected void gridView1_SelectedIndexChanged(object sender, EventArgs e)
{

int Id = (int)gridView1.DataKeys[gridView1.SelectedIndex].Value;

}



protected void gridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

int Id = (int)gridView1.DataKeys[e.RowIndex].Value;

}
0
 
LVL 22

Expert Comment

by:Tapan Pattanaik
ID: 24791587
hi dimensionav,

               Check the useful links.  

Using Parameters with the SqlDataSource Control  :

http://msdn.microsoft.com/en-us/library/z72eefad%28VS.80%29.aspx

Updating, Deleting records using GridView control:

http://www.dotnetfunda.com/articles/article29.aspx

ObjectDataSource Control:

http://dotnetforum.lk/forums/p/3384/14053.aspx

Pass Multiple Values from a GridView to Another Page using ASP.NET:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=147&AspxAutoDetectCookieSupport=1

Simple Insert, Select, Edit, Update and Delete in Asp.Net GridView control:

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:dimensionav
ID: 24794732
HI Guys

I have followed the example of tapanpattanaik using FormParameter. According to the article has to get the fields from gridview controls. Please notice that the controls has values only during update method and one of them is a DropDownList.

I am getting the error "Input string was not in a correct format"

Regards
' This is the gridview and datasource code
 
            <asp:GridView runat="server" 
                ID="gvPedidos" 
                ShowHeader="true"
                AutoGenerateColumns="False"
                RowStyle-CssClass="LineaDeContenidoCarrito" CellPadding="5" 
                AllowSorting="True" 
                DataSourceID="odsListadoPedidos" 
                DataKeyNames="Id_Pedido" 
                ShowFooter="true">
                <columns>
                    <asp:BoundField DataField="Id_Pedido" HeaderText="Pedido No." SortExpression="Pedido No." ItemStyle-Wrap="false" ItemStyle-Width="60" ReadOnly="true" ItemStyle-HorizontalAlign="center"></asp:BoundField>
                    <asp:BoundField DataField="Fecha" HeaderText="Fecha" SortExpression="Fecha" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-Wrap="false" ItemStyle-Width="80" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:BoundField DataField="Hora" HeaderText="Hora" DataFormatString="{0:t}" ItemStyle-Wrap="false" ItemStyle-Width="70" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:BoundField DataField="Id_Cliente" HeaderText="Id Cliente" SortExpression="Id Cliente" ItemStyle-Wrap="false" ItemStyle-Width="70" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:BoundField DataField="Id_Farrera" HeaderText="Id Farrera" SortExpression="Id Farrera" ItemStyle-Wrap="false" ItemStyle-Width="70" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:BoundField DataField="Email" HeaderText="Email" ItemStyle-Wrap="false" ItemStyle-Width="206" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:BoundField DataField="Nombre" HeaderText="Nombre" ItemStyle-Wrap="false" ItemStyle-Width="200" ReadOnly="true" ItemStyle-HorizontalAlign="Left"></asp:BoundField>
                    <asp:BoundField DataField="Plazo" HeaderText="Plazo" ItemStyle-Wrap="false" ItemStyle-Width="70" ReadOnly="true" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                    <asp:TemplateField HeaderText="Observaciones" ItemStyle-HorizontalAlign="Center">
                        <EditItemTemplate>
                            <asp:TextBox id="tbObservaciones" TextMode="MultiLine" runat="server" Text='<%# Bind("Observaciones") %>' Width="150" Height="50"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbObservaciones" runat="server" Text='<%# Bind("Observaciones") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>                
 
                    <asp:TemplateField HeaderText="Estatus" SortExpression="Estatus" ItemStyle-Wrap="false" ItemStyle-Width="97" ItemStyle-HorizontalAlign="Right">
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlEstatus" runat="server" SelectedValue='<%# Bind("Estatus") %>'>
                                <asp:ListItem Value="PENDIENTE">PENDIENTE</asp:ListItem>
                                <asp:ListItem Value="COMPLETADO">COMPLETADO</asp:ListItem>
                                <asp:ListItem Value="CANCELADO">CANCELADO</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lbEstatus" runat="server" Text='<%# Bind("Estatus") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" UpdateText="Actualizar" CancelText="Cancelar" />
                </columns>
 
                <RowStyle CssClass="LineaDeContenidoCarrito" />
                <FooterStyle CssClass="LineaDeTotalesCarrito" />  
            </asp:GridView>
 
           <asp:ObjectDataSource id="odsListadoPedidos" runat="server" 
                                  TypeName="DAV.TiendaEnLinea.v1.BusinessLogicLayer.BLLAdminEncabezadoPedidos" 
                                  SelectMethod="ObtieneListadoDePedidos" 
                                  UpdateMethod="ActualizaEncabezadoDePedido">
            <SelectParameters>
                <asp:querystringparameter name="FiltroPedidos" querystringfield="filtro" defaultvalue="0" Type="Int32" />
            </SelectParameters>
 
            <UpdateParameters>
                <asp:FormParameter FormField="Id_Pedido" Name="Id_Pedido" Type="string" />
                <asp:FormParameter FormField="Observaciones" Name="Observaciones" Type="string" />
                <asp:FormParameter FormField="Estatus" Name="Estatus" Type="string" />
            </UpdateParameters>
 
            </asp:ObjectDataSource>
 
 
'This is the BLL method that catches the parameters
        Public Shared Sub ActualizaEncabezadoDePedido(ByVal Id_Pedido As Integer, ByVal Observaciones As Integer, ByVal Estatus As Integer)
            Dim objPedido As DAV.TiendaEnLinea.v1.DataAccessLayer.DALAdminEncabezadoDePedidos = New DAV.TiendaEnLinea.v1.DataAccessLayer.DALAdminEncabezadoDePedidos
            objPedido.ModificaEncabezadoDePedido(Id_Pedido, Observaciones, Estatus)
        End Sub
 
 
' This is the DAL Method that updates the data
        Public Function ModificaEncabezadoDePedido(ByVal idpedido As Integer, ByVal observaciones As Integer, ByVal estatus As Integer) As Integer
            Dim sql As String
 
            sql = "UPDATE(PEDIDOS) " & _
                  "SET OBSERVACIONES='" & observaciones & "', ESTATUS='" & estatus & "' " & _
                  "WHERE ID_PEDIDO=" & idpedido
 
            Using con As New OleDbConnection(_ConnectionString)
                Dim cmd As OleDbDataAdapter = New OleDbDataAdapter(sql, con)
 
                Try
                    Dim Tabla As DataTable = New DataTable
                    cmd.Fill(Tabla)
                    Tabla.AcceptChanges()
                    Tabla.Clear()
 
                Catch ex As Exception
                    Console.WriteLine(ex.Message)
 
                End Try
            End Using
 
        End Function

Open in new window

0
 

Author Comment

by:dimensionav
ID: 24794762
One parameter wasn´t typed correctly, this is the new value:
<asp:FormParameter FormField="Id_Pedido" Name="Id_Pedido" Type="int32" />

The error is still present.

Regards
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24796255
just wondering if your other parameters should be Int as well...looks your BLL method takes all parameters of integer type
0
 

Author Comment

by:dimensionav
ID: 24796340
You´re Right

At this point BLL has one int parameter and two string ones. But the error keeps present.
I have attached the error image.

Regards


-047.jpg
0
 

Author Comment

by:dimensionav
ID: 24796441
Guys:
I have attached the files for better understanding.
Please change TXT extension according to the File Description details

Regards.
BLLAdminEncabezadoDePedidos.txt
DALAdminEncabezadoDePedidos.txt
listado-pedidos.txt
0
 

Author Comment

by:dimensionav
ID: 24806416
What I have noticed is that the value contained in the textbox of tbObservaciones (During Edit Event) is considered as int32, according to this part of the error message:

[Exception: demo is not a valid value for Int32.] In which demo is the value captured during test.

Regards.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24807992
Your BLL Method:
Public Shared Sub ActualizaEncabezadoDePedido(ByVal Id_Pedido As Integer, ByVal Observaciones As Integer, ByVal Estatus As Integer)

Your update Parameter:
    <UpdateParameters>
                <asp:FormParameter FormField="Id_Pedido" Name="Id_Pedido" Type="string" />
                <asp:FormParameter FormField="Observaciones" Name="Observaciones" Type="string" />
                <asp:FormParameter FormField="Estatus" Name="Estatus" Type="string" />
            </UpdateParameters>

That is the type mismatch I think.
               
           
0
 

Author Comment

by:dimensionav
ID: 24824954
What a novice I am !!!
I hope this won´t happen again.

Regards
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question