masterst

masterst

  • NA
  • 2
  • 0

Why won't my datagrid appear?

Jun 22 2004 10:42 AM
Hello. Here is my current code, which should display a datagrid, but its not. Let me explain what I am trying to accomplish. I have a drop down list where an account Number is selected and another one that contains territories. The goal is to be able to transfer accounts. Once the user clicks submit, I would like my datagrid to populate with the data that is selected in the stored procedure 'filldatagrid'. Basically the data inserted into the actual table are all numbers, but i want the datagrid to display the actual names. I am using @accountID in the stored procedure to match that item selected from the drop down with the appropriate account number in my accounts table. So, I hope this gives you an idea of what I am trying to do. I just can't seem to get the datagrid to appear. [code] Sub Page_Load(sender As Object, e As EventArgs) Dim rightNow as DateTime = DateTime.Now If day(RightNow) > 25 Then lbl_error.text = "You are not able to transfer accounts after the 25th of the month. Please try again next month." cmdInsert.visible=false else lbl_error.text = "Welcome to the Account Transfers Page." Dim sql as string if not Page.IsPostBack then sql = "select AccountID + ' - ' + AccountName as accnumber from Accounts order by AccountName" FillDropDownList(sql,AccNumber) end if if not Page.IsPostBack then sql = "select distinct territoryName from Territories where CloseDate is Null and territoryName not in ('IS 1','IS 2','IS 3','IS 4','IS 5')" FillDropDownList(sql,Toname) end if end if End Sub Sub FillDropDownList(sql as string, ddl as DropDownList) ' Create Connection Object, Command Object, Connect to the database Dim conn as New SQLConnection(connstr) Dim cmd as New SQLCommand(sql,conn) conn.open() ' Execute the SQL, Bind the results to the Dropdown List Control ddl.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) ddl.DataBind() End Sub Sub InsertData() Dim conn as SQLConnection Conn = New SQLConnection(connstr) Dim Cmd1 as SqlCommand Cmd1 = New SQLCommand("Insertaccounts",Conn) 'Declare the command type - a stored proc in this case Cmd1.commandType = CommandType.storedProcedure 'Add the parameters Cmd1.parameters.add("@AccountID",AccNumber.SelectedItem.Value) Cmd1.parameters.add("@Explanation",Explanation.text) dim cmd2 as SqlCommand Cmd2 = New SQLCommand("UpdateToTerritory",Conn) 'Declare the command type - a stored proc in this case Cmd2.commandType = CommandType.storedProcedure Cmd2.parameters.add("@AccountID",AccNumber.SelectedItem.Value) Cmd2.parameters.add("@ToName",ToName.SelectedItem.Value) conn.open() cmd1.ExecuteNonQuery() cmd2.ExecuteNonQuery() conn.Close() Response.redirect(return_page) end sub Sub cmdInsert_Click(sender As Object, e As EventArgs) InsertData() Response.redirect(return_page) End Sub Sub cmdCancel_Click(sender As Object, e As EventArgs) response.redirect(cancel_page) End Sub Protected Sub myDDL_SelectedIndexChanged(sender AS Object, e As EventArgs) binddata() End Sub Sub binddata() Dim conn as New SQLConnection(connstr) dim cmd4 as SqlCommand Cmd4 = New SQLCommand("filldatagrid", conn) Cmd4.commandType = CommandType.storedProcedure Cmd4.parameters.add("@AccountID",AccNumber.SelectedItem.Value) conn.open() ' Execute the SQL, Bind the results to the DataGrid Control transfers.DataSource = cmd4.ExecuteReader(CommandBehavior.CloseConnection) transfers.DataBind() Response.redirect(return_page) End Sub Account Transfers [/code]

Answers (1)



Account:


Transfer to:



Explanation: