Click to See Complete Forum and Search --> : Why doesn't my datagrid appear?


cusoxty
06-21-2004, 03:08 PM
Here is my code. However, I do not see my datagrid when the page loads. Why is this?


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(cancel_page)
end sub


Sub cmdInsert_Click(sender As Object, e As EventArgs)
InsertData()
End Sub

Sub cmdCancel_Click(sender As Object, e As EventArgs)
response.redirect(cancel_page)
End Sub

Sub BindDataToGrid()
Dim conn as New SQLConnection(connstr)

dim cmd4 as SqlCommand
Cmd4 = New SQLCommand("exec dbo.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()

End Sub



</script>
<html>
<head>
<title>Account Transfers</title>

</head>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<form onsubmit="return Validate(this)" action="transfers.aspx?Enter=True" method="POST" runat="server"

name="form1">
<table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr bgcolor="#000000">
<td valign="top" align="left">
&nbsp;</td>
</tr>
<tr>
<td width="100%" background="gor_white.gif">
<img height="1" src="images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#002041">
<td valign="top" align="left" width="100%" height="77">
<img height="77" src="images/header.gif" width="960" /></td>
</tr>
<tr>
<td width="100%" background="gor_white.gif">
<img height="1" src="images/gor_white.gif" width="20" border="NONE" /></td>
</tr>
<tr bgcolor="#36647e">
<td valign="top" align="left">
&nbsp;</td>
</tr>
<tr>
<td valign="center" align="middle" height="98%"><br />
<table bordercolor="#5e768e" cellspacing="0" cellpadding="5" width="900" bgcolor="#b6cce4"

border="1">
<tbody>
<tr><td colspan="2" align="center" valign="middle"><asp:Label id="lbl_error"

runat="server" width="500px" font="verdana" font-bold="True" forecolor="#002041">

</asp:Label></center></td></tr>
<td width="420" border="0" valign="top"><br />
<font face="Verdana" size="2"><b>Account: </b></font><br />

<asp:DropDownList id="AccNumber" name="AccNumber" runat="server"

DataValueField="accnumber" DataTextField="AccNumber" Width="420px"></asp:DropDownList>
<br /><br />

<font face="Verdana" size="2"><b>Transfer to:</b></font><br />
<asp:DropDownList id="ToName" name="ToName" runat="server"

DataValueField="TerritoryName" DataTextField="TerritoryName" Width="210px"></asp:DropDownList><br /><br /><br

/><font face="Verdana" size="2"><b>Explanation:</b></font><br />
<asp:TextBox id="Explanation" TextMode="MultiLine" runat="server" Width="420px"

Height="131px"></asp:TextBox><br /><br />

<center>

<asp:Button id="cmdInsert" onclick="cmdInsert_Click"

runat="server" Text="Request Transfer" type="submit"></asp:Button>
<asp:Button id="cmdCancel" onclick="cmdCancel_Click"

runat="server" Text="Cancel"></asp:Button>
</center>

</td><td border="1" width="480">
<asp:DataGrid id="transfers" runat="server">

</asp:DataGrid>


</td></tr>



</tbody>
</table>
</td>
</tr>
</form>

roteague
06-21-2004, 10:49 PM
Try this

Change:

Cmd4 = New SQLCommand("exec dbo.filldatagrid", conn)

To:

Cmd4 = New SQLCommand("dbo.filldatagrid", conn)

Otherwise it thinks its trying to find a stored procedure named "exec filldatagrid"

PeOfEo
06-21-2004, 11:46 PM
if the data grid does not display what does, do you get a bunch of stuff like this

<aspropDownList id="AccNumber" name="AccNumber" runat="server"

DataValueField="accnumber" DataTextField="AccNumber" Width="420px"></aspropDownList>

dead asp.net elements? Source code? Just wondering if the code executes.