I want to select a row in Default.aspx gridview to populate the corresponding textboxes in Default2.aspx. I am using the pubs database with the table authors with linq to sql. I don not want to have Default2.aspx to have a gridview just textboxes. Thank you.
Code
Default.aspxJava
asp:GridView ID="GridView1" runat="server">
Columns>
asp:TemplateField ShowHeader="False">
ItemTemplate>
asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Select" Text="Select">asp:LinkButton>
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>code behind:
C#
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext db = new DataClassesDataContext();
var products = from p in db.authors
select p;
GridView1.DataSource = products;
GridView1.DataBind();
}Default2.aspx
Java
au_lnameasp:TextBox ID="TextBox1" runat="server" />
br />
au_fname
asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
Ryan AlfordRank #1,411 · 1.2K reputationPosted Nov 19, 2008, 6:22 AM EST
Posted Nov 19, 2008, 2:02 PM EST
Ok, here is what I really what to do. How to I hide the DistributorID when load
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class manager_view_distributors : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AlternaDB.MarketingDataContext db = new AlternaDB.MarketingDataContext(); var products = from p in db.Distributors select new { p.DistributorID, Company_Name = p.CompanyName, Address = p.AddressLine1, p.City, Zip_Code = p.ZipCode, p.State, First_Name = p.Contact1FirstName, Last_Name = p.Contact1LastName, Area_Code = p.Contact1WorkAreaCode, Phone = p.Contact1WorkNumber, Num_Stores = p.NumStores, Num_DSC = p.NumDsc }; GridView1.DataSource = products; GridView1.DataBind(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { GridView1.PageSize = Int32.Parse(DropDownList1.SelectedValue); this.GetData(); } private void GetData() { GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; this.GetData(); } protected void LinkButton1_Click(object sender, EventArgs e) { if (this.rdoBtnListExportOptions.SelectedIndex == 1) { // the user wants all rows exported, turn off paging // and rebing the grid before sending it to the export // utility ExportExcelColumns(); this.GridView1.PageSize = 1000000; GridView1.DataBind(); } else if (this.rdoBtnListExportOptions.SelectedIndex == 2) { // the user wants just the first 100, // adjust the PageSize and rebind ExportExcelColumns(); this.GridView1.PageSize = 100; GridView1.DataBind(); } //Current Page export else if (this.rdoBtnListExportOptions.SelectedIndex == 0) { ExportExcelColumns(); GridView1.DataBind(); } GridViewExportUtil.Export("Customers.xls", this.GridView1); } private void ExportExcelColumns() { // pass the grid that for exporting ... AlternaDB.MarketingDataContext db = new AlternaDB.MarketingDataContext(); var dist = from d in db.Distributors select new { d.DistributorID, AccountType = SalonForm.DistAccountType.GetDistAccountTypeByValue((int)d.AccountType), AccountStatus = SalonForm.AccountStatus.GetAccountStatusByValue((int)d.AccountStatus), d.CompanyName, d.AddressLine1, d.AddressLine2, d.City, d.State, d.Country, d.ZipCode, d.Territory, d.NumDsc, d.NumStores, d.Website, Contact1Type = SalonForm.DistCustomerType.GetDistCustomerTypeByValue((int?)d.Contact1Type), d.Contact1FirstName, d.Contact1LastName, d.Contact1Email, d.Contact1WorkIntlPrefix, d.Contact1WorkAreaCode, d.Contact1WorkNumber, d.Contact1WorkExtension, d.Contact1CellIntlPrefix, d.Contact1CellAreaCode, d.Contact1CellNumber, d.Contact1CellExtension, d.Contact1ReceiveEnews, Contact2Type = SalonForm.DistCustomerType.GetDistCustomerTypeByValue((int?)d.Contact2Type), d.Contact2FirstName, d.Contact2LastName, d.Contact2Email, d.Contact2WorkIntlPrefix, d.Contact2WorkAreaCode, d.Contact2WorkNumber, d.Contact2WorkExtension, d.Contact2CellIntlPrefix, d.Contact2CellAreaCode, d.Contact2CellNumber, d.Contact2CellExtension, d.Contact2ReceiveEnews, Contact3Type = SalonForm.DistCustomerType.GetDistCustomerTypeByValue((int?)d.Contact3Type), d.Contact3FirstName, d.Contact3LastName, d.Contact3Email, d.Contact3WorkIntlPrefix, d.Contact3WorkAreaCode, d.Contact3WorkNumber, d.Contact3WorkExtension, d.Contact3CellIntlPrefix, d.Contact3CellAreaCode, d.Contact3CellNumber, d.Contact3CellExtension, d.Contact3ReceiveEnews, Contact4Type = SalonForm.DistCustomerType.GetDistCustomerTypeByValue((int?)d.Contact4Type), d.Contact4Firstname, d.Contact4LastName, d.Contact4Email, d.Contact4WorkIntlPrefix, d.Contact4WorkIntlAreaCode, d.Contact4WorkNumber, d.Contact4WorkExtension, d.Contact4CellIntlPrefix, d.Contact4CellAreaCode, d.Contact4CellNumber, d.Contact4CellExtension, d.Contact4ReceiveEnews, Contact5Type = SalonForm.DistCustomerType.GetDistCustomerTypeByValue((int?)d.Contact5Type), d.Contact5FirstName, d.Contact5LastName, d.Contact5Email, d.Contact5WorkIntlPrefix, d.Contact5WorkAreaCode, d.Contact5WorkNumber, d.Contact5WorkExtension, d.Contact5CellIntlPrefix, d.Contact5CellAreaCode, d.Contact5CellNumber, d.Contact5CellExtenstion, d.Contact5ReceiveEnews, d.DateCreated, d.Username, d.Password }; GridView1.DataSource = dist; } protected void BrowseDistGrid_SelectedIndexChanged(object sender, EventArgs e) { } protected void rdoBtnListExportOptions_SelectedIndexChanged(object sender, EventArgs e) { } protected void LinkButton1_Click1(object sender, EventArgs e) { GridViewRow gvr = (GridViewRow)((LinkButton)sender).Parent.Parent; //get that selected row //string AccountType = gvr.Cells[16].Text; string CompanyName = gvr.Cells[2].Text; string Address1 = gvr.Cells[3].Text; Response.Redirect("Distributor.aspx?CompanyName=" + CompanyName + "&Address1=" + Address1 ); //redirect to next page with selected values } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header | e.Row.RowType == DataControlRowType.DataRow) { e.Row.Controls[1].Visible = false; } } }Ryan AlfordRank #1,411 · 1.2K reputationPosted Nov 19, 2008, 4:00 PM EST
Posted Nov 19, 2008, 4:12 PM EST
Ryan AlfordRank #1,411 · 1.2K reputationPosted Nov 19, 2008, 5:50 PM EST
Posted Nov 19, 2008, 6:07 PM EST