Results 1 to 4 of 4

Thread: Pass data to next form in VB (simply in C# - but prefer VB, if pos)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    1

    Pass data to next form in VB (simply in C# - but prefer VB, if pos)

    Hi

    This is simple in C# but as I have already used quite a bit of of VB in a project I’m doing I was hopeing to do this is VB.
    Can it be done (simply)
    Say I have an aspGridView with 3 columns (fed from a database)
    with an ItemTemplate Button - like this
    Code:
    <asp:GridView id="MyGridView" runat="server" AutoGenerateColumns="False" DataSourceID="MySource">
    <Columns>
    <asp:boundfield DataField="ID" HeaderText="ID" ReadOnly="True"></asp:boundfield>
    <asp:boundfield DataField="2ndField" HeaderText="2nd"</asp:boundfield>
    <asp:boundfield DataField="3rd Field" HeaderText="3rd"</asp:boundfield>
    <asp:TemplateField>
     <ItemTemplate>
    <asp:Button ID="Button1" runat="server" CausesValidation="false" 
    Text="Select" OnClick="Button1_Click"></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    
    To send these details to the next form (form2.aspx) I just used this
    
    <script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
    Button btn = sender as Button;
     GridViewRow row = (GridViewRow)btn.NamingContainer;
                string ID_val = row.Cells[0].Text;
                string 2nd_val = row.Cells[1].Text;
                string 3rd = row.Cells[2].Text;
    
     Response.Redirect(String.Format("form2.aspx?ID={0}&2nd={1} &3rd={2} ", 
    ID_val, 2nd_val, 3rd_val,));
    }</script>
    In the next form I would use

    Code:
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {txtID.Text = Request.QueryString["ID"];
    txt_2nd.Text = Request.QueryString["2nd"];
    txt_3rd.Text = Request.QueryString["3rd"];
    }</script>
    How would I do this in VB (simply)

    Thank you

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Pass data to next form in VB (simply in C# - but prefer VB, if pos)

    The same way... only using VB syntax.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Pass data to next form in VB (simply in C# - but prefer VB, if pos)

    Welcome to the forums!

    To send these details to the next form (form2.aspx) I just used this
    <script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
    Button btn = sender as Button;
    GridViewRow row = (GridViewRow)btn.NamingContainer;
    string ID_val = row.Cells[0].Text;
    string 2nd_val = row.Cells[1].Text;
    string 3rd = row.Cells[2].Text;


    Response.Redirect(String.Format("form2.aspx?ID={0}&2nd={1} &3rd={2} ",
    ID_val, 2nd_val, 3rd_val,));
    }</script>


    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {txtID.Text = Request.QueryString["ID"];
    txt_2nd.Text = Request.QueryString["2nd"];
    txt_3rd.Text = Request.QueryString["3rd"];
    }</script>
    I'd put those server side codes (c# or vb.net) in code-behind (form2.aspx.cs or form2.aspx.vb) rather than inline coding.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Pass data to next form in VB (simply in C# - but prefer VB, if pos)

    Thread moved from the 'ASP, VB Script' forum to the 'ASP.Net' forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width