VB .Net

Discussion in 'Software' started by jsanthoshkumar86, Jan 2, 2008.

  1. jsanthoshkumar86

    jsanthoshkumar86

    Joined:
    Jan 2, 2008
    Messages:
    2
    Let me share some of the concepts that i have leared in vb.net

    DATAGRID CONTROL

    ADDING A NEW ROW TO DATAGRID ON A CLICK EVENT .. WITHOUT BACKEND CONNECTIVITY


    FIRST

    add a datagrid control in the design window... here i hav used some 7 template columns and a edit column

    the html code for this is ...


    HTML

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="comp.aspx.vb" Inherits="portal.comp"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>comp</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout" background="file:///C:\Inetpub\wwwroot\portal\Buttons\bg.jpg">
    <form id="Form1" method="post" runat="server">
    <TABLE id="Table1" style="Z-INDEX: 102; LEFT: 40px; WIDTH: 792px; POSITION: absolute; TOP: 48px; HEIGHT: 320px"
    cellSpacing="1" cellPadding="1" width="792" background="file:///C:\Inetpub\wwwroot\portal\Buttons\bg.jpg"
    border="0">
    <TR>
    <TD>
    <P>&nbsp;&nbsp;
    <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False" BorderColor="#E7E7FF" BorderStyle="None"
    BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Horizontal" Width="784px">
    <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
    <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
    <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
    <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
    <Columns>
    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
    <asp:BoundColumn HeaderText="RESOURCE NAME"></asp:BoundColumn>
    <asp:BoundColumn DataField="RSRC_ID" HeaderText="RESOURCE ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="TECH_ID" HeaderText="TECHNOLOGY"></asp:BoundColumn>
    <asp:BoundColumn DataField="EXPRNC" HeaderText="EXPERIENCE"></asp:BoundColumn>
    <asp:BoundColumn DataField="PRFNCY" HeaderText="PROFICIENCY"></asp:BoundColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Button id="Button5" runat="server" CausesValidation="false" Text="Delete" CommandName="del"></asp:Button>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:ButtonColumn Text="Add" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>
    </asp:datagrid></P>
    </TD>
    </TR>
    </TABLE>
    <TABLE id="Table3" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 16px" cellSpacing="1"
    cellPadding="1" width="300" border="0">
    <TR>
    <TD>
    <asp:HyperLink id="HyperLink5" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\portal\Buttons\blue\PersonalDetails_White.jpg"
    Target="main" NavigateUrl="PersonalDetails.aspx">Personal Details</asp:HyperLink></TD>
    <TD>
    <asp:HyperLink id="HyperLink2" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\portal\Buttons\blue\CompetencyDetails_Blue.jpg"
    Target="main" NavigateUrl="comp.aspx">Competancy Details</asp:HyperLink></TD>
    <TD>
    <asp:HyperLink id="HyperLink3" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\portal\Buttons\blue\ProjectDetails_White.jpg"
    Target="main" NavigateUrl="MiscDetails.aspx">Misc Details</asp:HyperLink></TD>
    <TD>
    <asp:HyperLink id="HyperLink4" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\portal\Buttons\blue\MachineDetails_White.jpg"
    Target="main" NavigateUrl="MchnDtls.aspx">Machine Details</asp:HyperLink></TD>
    </TR>
    </TABLE>
    </form>
    </body>
    </HTML>
    Last edited: Jan 2, 2008
    jsanthoshkumar86, Jan 2, 2008
    #1
    1. Advertising

  2. jsanthoshkumar86

    jsanthoshkumar86

    Joined:
    Jan 2, 2008
    Messages:
    2
    continued..........CODE BEHING

    CODE BEHIND

    in the code behing in using a datatable concept rather ther going for a db connectivity .. as it wod make more network traffic...
    and i can update the entire table finally
    here in the datagrid im using a buttons namely add and delete...
    add used to insert an empty column in the datatable and its binded to the datagrid
    and delete button deltes the particular row

    the edit column obviously used for updating the values..
    here in update ... the logic is .. to insert a new row at a position useing INSERTAT command and to delete the below row after inserting


    here is the code for that

    VB.NET CODE




    Imports System.Data.SqlClient
    Public Class comp
    Inherits System.Web.UI.Page
    ' Dim ds As DataSet

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents HyperLink4 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink3 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink2 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink5 As System.Web.UI.WebControls.HyperLink

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object


    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here




    If Me.IsPostBack = False Then



    'Dim ds As DataSet = GetDataSet()
    'dg1.DataSource = ds.Tables("competancy")
    'BindGrid(ds)
    Session("id") = 166864
    Convert.ToString(Session("id"))
    End If




    End Sub
    Public Sub BindGrid(ByVal ds As DataSet)
    dg1.DataSource = ds.Tables("competancy")
    Me.DataBind()
    End Sub

    Public Function GetDataSet() As DataSet
    Dim select1 As String
    select1 = "Select * from tblcmptncyDtls"
    Dim oConn As New SqlConnection("Server = ctsinnvlsdbb;user id=training;password=password;database=training")
    oConn.Open()
    Dim cmd As New SqlCommand(select1, oConn)
    Dim da As New SqlDataAdapter(select1, oConn)
    Dim ds As New DataSet("competancy")
    da.Fill(ds, "competancy")
    oConn.Close()
    Return ds

    End Function


    Private Sub dg1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.EditCommand
    dg1.EditItemIndex = e.Item.ItemIndex
    Dim ds As DataSet = GetDataSet()
    BindGrid(ds)
    End Sub

    Private Sub Button5_Onclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dg1.SelectedIndexChanged


    'dg1.Rows.RemoveAt(e.RowIndex)


    Dim oConn1 As New SqlConnection("Server = ctsinnvlsdbb;user id=training;password=password;database=training")
    oConn1.Open()
    Dim da1 As New SqlDataAdapter("delete from tblcmptncyDtls WHERE PRFNCY = ''", oConn1)
    Dim ds1 As New DataSet("Details1")
    da1.Fill(ds1, "Details1")
    oConn1.Close()
    Response.Redirect("comp.aspx")

    End Sub

    Private Sub dg1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.DeleteCommand
    Dim oConn1 As New SqlConnection("Server = ctsinnvlsdbb;user id=training;password=password;database=training")
    oConn1.Open()
    Dim da1 As New SqlDataAdapter("insert into tblcmptncyDtls(RSRC_ID,TECH_ID,EXPRNC,PRFNCY)values('166864','001','','')", oConn1)
    Dim ds1 As New DataSet("Details1")
    da1.Fill(ds1, "Details1")
    oConn1.Close()
    Response.Redirect("comp.aspx")
    End Sub
    End Class



    ........................

    the save button here inserts the entire datatable into the database...
    jsanthoshkumar86, Jan 2, 2008
    #2
    1. Advertising

  3. jsanthoshkumar86

    urstop

    Joined:
    Oct 17, 2007
    Messages:
    11
    Location:
    London
    I think it would be good to put it in a article section or something like that instead of the forum section.

    Thanks,
    UrStop
    urstop, Jan 2, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brunswick Lowe

    vb.net vs. studio.net

    Brunswick Lowe, Jul 30, 2003, in forum: MCSD
    Replies:
    5
    Views:
    3,287
    John S
    Aug 3, 2003
  2. Alex
    Replies:
    0
    Views:
    489
  3. Cowboy \(Gregory A. Beamer\)

    Take MCSD.NET with VB.NET and C#.NET in the same time?

    Cowboy \(Gregory A. Beamer\), Jan 1, 2004, in forum: MCSD
    Replies:
    1
    Views:
    476
    The Fox
    Jan 1, 2004
  4. Ivor

    C#.Net or VisualBasic.Net

    Ivor, Aug 18, 2004, in forum: MCSD
    Replies:
    8
    Views:
    1,045
    The Poster Formerly Known as Kline Sphere
    Aug 22, 2004
  5. london1919
    Replies:
    1
    Views:
    2,916
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
Loading...

Share This Page