Solved

How to make one gridview field editable through VB code?

Posted on 2013-01-25
10
251 Views
Last Modified: 2013-02-12
I have the following application:

gridview
I am trying to make the Lineas Auditads an editable field in my gridview through the VB code. Can someone help?

    Dim dt As DataView

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray
        Chart1.ChartAreas(0).AxisY2.MajorGrid.LineColor = Color.LightGray
        Chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.Transparent
        Chart1.ChartAreas(0).AxisX.LabelStyle.Font = New Font("Arial", 8)
        Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 8)
        Chart1.ChartAreas(0).AxisY2.LabelStyle.Font = New Font("Arial", 8)

        Chart1.CallbackStateContent = CallbackStateContent.SeriesDataOnly
        Me.Page.ClientScript.RegisterStartupScript(GetType(Dundas.Charting.WebControl.Chart), "Chart1_Callback", "window.setInterval(""" + Chart1.CallbackManager.GetCallbackAsyncMethodReference(Timer, "") + """, 60000);", True)
        Chart1.Titles(0).Text = "% de Lineas Auditadas de Ensamble"

        Dim dtmTest As Date
        Dim strShift As String
        Dim sqlStr As String
        dtmTest = TimeOfDay

        Select Case dtmTest
            Case "6:50:00 AM" To "12:50:00 PM"
                strShift = "1"
                sqlStr = "select l.line  as [Linea],isnull(e.Total_Qty, 0) as [QTY de Lineas de Ensamble],isnull(e.Progress_Qty, 0) as [Lineas Auditadas],isnull ( round(( e.Progress_Qty * 100)/e.Total_Qty,0), 0) as [Progreso] from Lenovo_Lines l LEFT Join Lenovo_Events e ON  e.Line_Key = l.Line_Key AND e.Event_Date >= CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE(), 120) , 120) AND e.Event_Date < CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE() + 1, 120) , 120) and shift_Key =1"
            Case "12:50:00 PM" To "6:50:00 PM"
                strShift = "2"
                sqlStr = "select l.line  as [Linea],isnull(e.Total_Qty, 0) as [QTY de Lineas de Ensamble],isnull(e.Progress_Qty, 0) as [Lineas Auditadas],isnull ( round(( e.Progress_Qty * 100)/e.Total_Qty,0), 0) as [Progreso] from Lenovo_Lines l LEFT Join Lenovo_Events e ON  e.Line_Key = l.Line_Key AND e.Event_Date >= CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE(), 120) , 120) AND e.Event_Date < CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE() + 1, 120) , 120) and shift_Key =2"
            Case "6:50:00 PM" To "12:50:00 AM"
                strShift = "3"
                sqlStr = "select l.line  as [Linea],isnull(e.Total_Qty, 0) as [QTY de Lineas de Ensamble],isnull(e.Progress_Qty, 0) as [Lineas Auditadas],isnull ( round(( e.Progress_Qty * 100)/e.Total_Qty,0), 0) as [Progreso] from Lenovo_Lines l LEFT Join Lenovo_Events e ON  e.Line_Key = l.Line_Key AND e.Event_Date >= CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE(), 120) , 120) AND e.Event_Date < CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE() + 1, 120) , 120) and shift_Key =3"
            Case "12:50:00 AM" To "6:50:00 AM"
                strShift = "4"
                sqlStr = "select l.line  as [Linea],isnull(e.Total_Qty, 0) as [QTY de Lineas de Ensamble],isnull(e.Progress_Qty, 0) as [Lineas Auditadas],isnull ( round(( e.Progress_Qty * 100)/e.Total_Qty,0), 0) as [Progreso] from Lenovo_Lines l LEFT Join Lenovo_Events e ON  e.Line_Key = l.Line_Key AND e.Event_Date >= CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE(), 120) , 120) AND e.Event_Date < CONVERT(datetime, CONVERT(VARCHAR(10), GETDATE() + 1, 120) , 120) and shift_Key =4"
        End Select

        Dim sConn As String = ConfigurationManager.ConnectionStrings("BusDevConnectionString").ToString
        Dim myConnection As SqlConnection = New SqlConnection(sConn)
        Dim myCommand As SqlDataAdapter = New SqlDataAdapter
        myCommand = New SqlDataAdapter(sqlStr, myConnection)
        Dim ds As DataSet = New DataSet()
        myCommand.Fill(ds)

        Dim source As New DataView(ds.Tables(0))
        Chart1.DataSource = source
        Chart1.Series(0).ValueMemberX = "Linea"
        Chart1.Series(0).ValueMembersY = "Progreso"
        Chart1.DataBind()
        GridView1.AutoGenerateSelectButton = False
        GridView1.DataSource = dt
        GridView1.DataBind()

        Dim sqlStrGV As String
        Dim Conn As String = ConfigurationManager.ConnectionStrings("BusDevConnectionString").ToString
        Dim myGVConnection As SqlConnection = New SqlConnection(Conn)
        sqlStrGV = sqlStr

        Dim myCommandGV As SqlDataAdapter = New SqlDataAdapter
        myCommandGV = New SqlDataAdapter(sqlStrGV, myGVConnection)
        GridView1.AutoGenerateSelectButton = True
        Dim dsGV As DataSet = New DataSet()
        myCommandGV.Fill(dsGV)
        Dim sourceGV As DataView
        sourceGV = New DataView(dsGV.Tables(0))
        GridView1.AutoGenerateSelectButton = False
        GridView1.DataSource = sourceGV
        GridView1.DataMember = dsGV.Tables(0).TableName
        GridView1.DataBind()
        GridView1.AllowSorting = True
        Session("DataSource") = sourceGV

    End Sub

Open in new window

0
Comment
Question by:JessyRobinson1234
  • 5
  • 2
10 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 38820762
0
 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 250 total points
ID: 38825967
to make only one column editable and remaining not then u can set  readonly="true"

<columns>
      <asp:boundfield datafield="ID" readonly="true" headertext="ID"/>
      <asp:boundfield datafield="Name"headertext="Name"/>
</columns>

Need More visit  :http://www.codeproject.com/Articles/18136/Edit-Individual-GridView-Cells-in-ASP-NET
0
 

Author Comment

by:JessyRobinson1234
ID: 38830637
I get the error: Update_Events_GV has too many arguments specified.

Here's my code:

<asp:GridView ID="GridView1" DataSourceID="sdsEvents" DataKeyNames="Linea" runat="server" Height="186px" Width="713px" CellPadding="4" ForeColor="#333333" GridLines="None" BorderStyle="Solid" BorderWidth="2px" BorderColor="#D8D8D8" PageSize="4" AutoGenerateColumns="False">
                                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <Columns>                                       
                                        <asp:CommandField ShowEditButton="True" />
                                        <asp:BoundField DataField="Event_Key" HeaderText="Event_Key" InsertVisible="true" SortExpression="Event_Key"  ReadOnly="true" />
                                        <asp:BoundField DataField="Linea" HeaderText="Linea" SortExpression="Linea" ReadOnly="true" />
                                        <asp:BoundField DataField="QTY de Lineas de Ensamble" HeaderText="QTY de Lineas de Ensamble" SortExpression="QTY de Lineas de Ensamble"  ReadOnly="true" />
                                        <asp:BoundField DataField="Progress_Qty" HeaderText="Progress_Qty" SortExpression="Progress_Qty"  ReadOnly="false" />
                                        <asp:TemplateField HeaderText="Lineas Auditadas" SortExpression="Lineas Auditadas">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Progress_Qty") %>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Progress_Qty") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="progress_Pct" HeaderText="progress_Pct" SortExpression="progress_Pct" ReadOnly="true" />
                                    </Columns>
                                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                    <EmptyDataTemplate>
                                        <center>
                                            No dataset selected. Please click on the barchart to populate data.
                                        </center>
                                    </EmptyDataTemplate>
                                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                                    <EditRowStyle BackColor="#999999" />
                                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="sdsEvents" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>" 
                                    SelectCommand="View_Events_GV" UpdateCommand="Update_Events_GV" UpdateCommandType="StoredProcedure"  SelectCommandType="StoredProcedure">
                                    <SelectParameters>
                                        <asp:ControlParameter ControlID="ShiftKey" Name="StrShift" PropertyName="Text" Type="String" />            
                                    </SelectParameters>
                                    <UpdateParameters>
                                        <asp:Parameter Name="Event_Key" Type="Int32" />
                                        <asp:Parameter Name="Progress_Qty" Type="Int32" />
                                    </UpdateParameters>
                                </asp:SqlDataSource>

Open in new window


Stored Procedure:

ALTER PROCEDURE [dbo].[Update_Events_GV]
    @Event_Key int,
 	@Progress_Qty int
AS
BEGIN

    SET NOCOUNT ON;
	DECLARE @Msg nvarchar(max)

  BEGIN
         UPDATE Lenovo_Events
set
	Progress_Qty = @Progress_Qty
where Event_Key = @Event_Key

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38832034
And the code that sets the parameter values?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JessyRobinson1234
ID: 38866009
I've requested that this question be closed as follows:

Accepted answer: 0 points for JessyRobinson1234's comment #a38830637

for the following reason:

thank you I got it working
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38863992
Without any help from here?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38866010
Either select the comment which helped or delete the question.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38870141
Split between http:#a38820762 and http:#a38825967
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now