codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Sorry I posted In the wrong Place,,,,I need Help with my DataGrid  mcupryk at 14:36 on Monday, September 13, 2004
 

How do I bind a dropdownlist to a multiple table query that is

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[Users_Select] AS SELECT
tbl_Users.UserID,
tbl_Users.FullName,
tbl_Users.UserName,
tbl_Users.ReportToID,
tbl_Users_AccessLevelID.AccessLevel,
tbl_Users_StoreID.Store,
tbl_Users.UserID FROM tbl_Users_AccessLevelID
INNER JOIN tbl_Users ON (tbl_Users_AccessLevelID.AccessLevelID = tbl_Users.AccessLevelID)
INNER JOIN tbl_Users_StoreID ON (tbl_Users.StoreID = tbl_Users_StoreID.StoreID)

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


Where Store is 1 = > name1
2 = > name2
3 = > name3

In the dropdownlist the values should be name1 - name3


public class Webform : System.Web.UI.Page
{
protected DataView TempDataView = new DataView();
protected System.Web.UI.WebControls.DataGrid DataGrid1;
// Only run this code the first time the page is loaded.
// The code inside the IF statement is skipped when you resubmit the page.


private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();

}

}

public void EditDataGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}

public void CancelDataGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
BindGrid();
}

public void UpdateDataGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Display information about changes
DropDownList ddlStore = (DropDownList) e.Item.FindControl("ddlStore");
Response.Write("<h2>You selected " + ddlStore.SelectedItem.Text + " (" + ddlStore.SelectedValue + ")</h2>");

DataGrid1.EditItemIndex = -1;
BindGrid();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.CancelDataGrid);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.EditDataGrid);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.UpdateDataGrid);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion



public void BindGrid()
{
// Put user code to initialize the page here
//Create a connection to the SQL Server; modify the connection string for your environment.
SqlConnection MyConnection = new SqlConnection("server=(local);database=MSPOS;UID=sa;PWD=;");

//Create a DataAdapter, and then provide the name of the stored procedure.
SqlDataAdapter MyDataAdapter = new SqlDataAdapter("prc_Select_Users", MyConnection);

//Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
MyConnection.Open();
MyDataAdapter.SelectCommand.ExecuteNonQuery();
DataSet ds = new DataSet();
//Fill the DataSet with the rows that are returned.
MyDataAdapter.Fill(ds, "prc_Select_Users");
//Set the data source for the DataGrid as the DataSet that holds the rows.
DataGrid1.DataSource = ds.Tables["prc_Select_Users"].DefaultView;
//NOTE: If you do not call this method, the DataGrid is not displayed!
DataGrid1.DataBind();

MyDataAdapter.Dispose(); //Dispose the DataAdapter.
MyConnection.Close(); //Close the connection.
}

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

}


private void MyDataGrid_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;

TableCell cell = list.Parent as TableCell;
DataGridItem item = cell.Parent as DataGridItem;

int index = item.ItemIndex;
string content = item.Cells[0].Text;

Response.Write(
String.Format("Row {0} contains {1}", index, content)
);

}

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}


I am having a heck of a time with this, If I am in the wrong place please direct me to the right one. If you know how to bind the dropdownlist to a a multiple table quey could you please tell me. I would appreciate it .

Sincerely,

Mathieu Cupryk








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Sorry I posted In the wrong Place,,,,I need Help with my DataGrid
•  Help with a DataGrid
•  Help: FSO -> Network Drive
•  Server Error in `/` Application.
•  URL code
•  Paging in DataList
•  Re: servlet login
•  Re: urgent!Need help please.......
•  Re: MailAttachment


Recent Articles
Simple Thumbnail Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)
Function to Return Alpha Characters Only
The OSI Reference Model - A Clear and Concise Illustration !


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004