Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Professional Peoples:
Plz Help Me To Resolve This Problem.
The Problem Is THat
i have two asp.net web pages one(GridCreateUser.aspx) has gridview and other(CreateUser.aspx) has controls like textboxes

i am using vb.net as code behind.

now i want when i click on edit link in my gridview on page gridcreateuser.aspx the appropriate data will bind to my createuser.aspx page???????????how i can do this.

I know in desktop application i can do this by
createuser.textbox1.text=Trim(ds.Tables("Employee1").Rows(0)(0))

but how in Browser based asp.net application????????????????

thanks in advance!!!!!!!!!!!!!!!1
Posted

1 solution

Not the best piece of code in the world, but, you can have a look at the following simple implementation and follow a similar approach:

Note : Pardon the C# code. I don't know VB.NET and you have to convert these codes to VB.NET to run

Aspx:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                Width="215px" OnRowCommand="GridView1_RowCommand"
                onrowdatabound="GridView1_RowDataBound">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="Name" />
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                                CommandName="Edit" Text="Edit"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    </div>
    </form>
</body>
</html>



And, CodeBehind (Written in C# as I do not know VB.net, please convert into VB.NET)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    //A simple Person class
    public class Person
    {
        public int Id
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }
        public Person(int Id, string Name)
        {
            this.Id = Id;
            this.Name = Name;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Populating some dummy data in the GridView. In reality, you should populate these from the database
            IList items = new ArrayList();

            items.Add(new Person(1, "Peter"));
            items.Add(new Person(2, "John"));
            items.Add(new Person(3, "Shubho"));

            GridView1.DataSource = items;
            GridView1.DataBind();
        }
    }
   
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            //User clicked Edit link
            int userId = Convert.ToInt32(e.CommandArgument);

             //Redirect to your create page here. In the CreateUser.aspx, load the user with the supplied userId from the database and populate user data in the text box

            Response.Redirect(string.Format("CreateUser.aspx?Id={0}",userId));
           
        }
    }

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
     {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton link = e.Row.FindControl("LinkButton1") as LinkButton;
            if (link != null)
            {
                //Set the CommandArgument to Person's Id for the Link buttons so that, when user clicks the Edit link, the Id value can be retrieved from the CommandArgument
                link.CommandArgument = ((Person)e.Row.DataItem).Id.ToString();
            }
        }
    } 
}


I provided you the codes because somehow I feel you are kind of new in Asp.net and thought this will help you.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900