Click here to Skip to main content
15,900,258 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how to make invisible comboBox visible in GridView Pin
Sherin Iranimose8-May-07 18:22
Sherin Iranimose8-May-07 18:22 
GeneralRe: how to make invisible comboBox visible in GridView Pin
AaronNeo8-May-07 22:58
AaronNeo8-May-07 22:58 
GeneralRe: how to make invisible comboBox visible in GridView [modified] Pin
Sherin Iranimose8-May-07 23:43
Sherin Iranimose8-May-07 23:43 
GeneralRe: how to make invisible comboBox visible in GridView Pin
AaronNeo9-May-07 17:48
AaronNeo9-May-07 17:48 
GeneralRe: how to make invisible comboBox visible in GridView Pin
Sherin Iranimose9-May-07 18:19
Sherin Iranimose9-May-07 18:19 
GeneralRe: how to make invisible comboBox visible in GridView Pin
AaronNeo11-May-07 0:29
AaronNeo11-May-07 0:29 
GeneralRe: how to make invisible comboBox visible in GridView Pin
Sherin Iranimose11-May-07 0:35
Sherin Iranimose11-May-07 0:35 
Questioncode behind [modified] Pin
Lohchubh8-May-07 14:57
Lohchubh8-May-07 14:57 
i am new to asp.net and have a code that works fine inline but doesnot work in vs 2005 code behind. someone please help
when the page loads all dropdownlist are empty however when you click search
button all results are displayed.on clicking paging number for next record it
again shows empty dropdown list.



here is the code:
code behind

Imports System

Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls







Imports System.Data
Imports System.Data.Odbc

Partial Class _Default
Inherits System.Web.UI.Page




Sub btnSearch_OnClick(ByVal sender As Object, ByVal e As EventArgs)
dgrdProducts.CurrentPageIndex = 0
Page_Load()
End Sub





Sub PageChange(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
dgrdProducts.CurrentPageIndex = e.NewPageIndex
Page_Load()
End Sub




Dim strBackGroundColor As String

Sub dropColors_SelectedIndexChanged(ByVal s As Object, ByVal e As EventArgs)





strBackGroundColor = dropColors.SelectedValue.ToString




End Sub


Dim strBackGroundColor2 As String

Sub dropColors_SelectedIndexChanged2(ByVal s As Object, ByVal e As EventArgs)
strBackGroundColor2 = dropColors2.SelectedValue.ToString
End Sub


Dim strBackGroundColor3 As String

Sub dropColors_SelectedIndexChanged3(ByVal s As Object, ByVal e As EventArgs)
strBackGroundColor3 = dropColors3.SelectedValue.ToString
End Sub














Sub Page_Load()



'1. Create a connection

Dim myConnection As New OdbcConnection("DSN=store")

Dim myConnection2 As New OdbcConnection("DSN=store")

Dim myConnection3 As New OdbcConnection("DSN=store")


'2. Create the command object, passing in the SQL string

Const strSQL As String = "select distinct category from products"

Const strSQL2 As String = "select distinct product from products"


Const strSQL3 As String = "select distinct price from products"


'Const strSQL as String = "SELECT distinct category, product, price FROM products"






'Const strSQL as String = "SELECT FAQID, LEFT(Description, 40) + '...' AS Description " & _
'"FROM tblFAQ ORDER BY Description"


Dim myCommand As New OdbcCommand(strSQL, myConnection)

Dim myCommand2 As New OdbcCommand(strSQL2, myConnection2)


Dim myCommand3 As New OdbcCommand(strSQL3, myConnection3)

'3. Create the DataReader

myConnection.Open()
myConnection2.Open()
myConnection3.Open()

Dim objDR As OdbcDataReader
Dim objDR2 As OdbcDataReader
Dim objDR3 As OdbcDataReader

objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

objDR2 = myCommand2.ExecuteReader(CommandBehavior.CloseConnection)


objDR3 = myCommand3.ExecuteReader(CommandBehavior.CloseConnection)

'Databind the DataReader to the listbox Web control

If Not IsPostBack Then




dropColors.DataSource = objDR
dropColors.DataBind()

dropColors2.DataSource = objDR2
dropColors2.DataBind()

dropColors3.DataSource = objDR3
dropColors3.DataBind()


'Add a new listitem to the beginning of the listitemcollection

dropColors.Items.Insert(0, New ListItem("-- Choose a category --"))
dropColors2.Items.Insert(0, New ListItem("-- Choose a product --"))
dropColors3.Items.Insert(0, New ListItem("-- Choose price range --"))


End If








Dim dstProducts As DataSet

Dim dadProducts As OdbcDataAdapter





Dim strSQLQuery As String
Dim objConnection As OdbcConnection

Dim objCommand As OdbcCommand

Dim strBackGroundColor As String

Dim strBackGroundColor2 As String
Dim strBackGroundColor3 As String

strBackGroundColor = dropColors.SelectedValue.ToString
'strBackGroundColor = lstFAQs.SelectedValue.ToString

'Response.Write(strBackGroundColor)
'Response.End()
strBackGroundColor2 = dropColors2.SelectedValue.ToString

'strBackGroundColor2 = lstFAQs2.SelectedValue.ToString
'Response.Write("strBackGroundColor2")

strBackGroundColor3 = dropColors3.SelectedValue.ToString
'strBackGroundColor3 = lstFAQs3.SelectedValue.ToString
'Response.Write("strBackGroundColor3")
'Response.End()
If Len(Trim(strBackGroundColor)) >= 0 Then
' Set up our connection.





' Grab Products Table
dstProducts = New DataSet()



objConnection = New OdbcConnection("DSN=store")



' Set up our SQL query text.
strSQLQuery = "SELECT StoreID, category, product, status, description, price, stock, moreinformation, photo, priceactual, buy " _
& "FROM products " _
& "WHERE category LIKE '%" & Replace(strBackGroundColor, "'", "''") & "%' " _
& "AND product LIKE '%" & Replace(strBackGroundColor2, "'", "''") & "%' " _
& "AND price LIKE '%" & Replace(strBackGroundColor3, "'", "''") & "%' " _
& "ORDER BY status;"





'Response.Write(strSQLQuery)
'Response.End()


objCommand = New OdbcCommand(strSQLQuery, objConnection)



dadProducts = New OdbcDataAdapter(objCommand)



dadProducts.Fill(dstProducts, "products")



' Bind to DataGrid
dgrdProducts.DataSource = dstProducts
dgrdProducts.DataBind()


Else

End If





End Sub


End Class


here is aspx front end

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<table border=0 width=300 height=100 align=center>

<tr>

<td align=center>
<td >
<asp:DropDownList id="dropColors" runat="server" Rows="1"
OnSelectedIndexChanged="dropColors_SelectedIndexChanged"
AutoPostBack="false"

DataTextField="category" DataValueField="category" />


</td>

<td align=center>
<font color=black><b>Product :</b></font></td>
<td >
<asp:DropDownList id="dropColors2" runat="server" Rows="1"
OnSelectedIndexChanged="dropColors_SelectedIndexChanged2"
AutoPostBack="false"
DataTextField="Product" DataValueField="Product" />

</td>

<td align=center>
<font color=black><b>Price :</b></font></td>
<td >
<asp:DropDownList id="dropColors3" runat="server" Rows="1"
OnSelectedIndexChanged="dropColors_SelectedIndexChanged3"
AutoPostBack="false"
DataTextField="Price" DataValueField="Price" />

</td>

<td colspan=2 align=center>

<asp:Button id="btnSearch" runat="server"
Text = "Search"
OnClick = "btnSearch_OnClick"
/>

</td>


</tr>


</table>


<asp:DataGrid id="dgrdProducts" runat="server"


AutoGenerateColumns="False"
EnableViewState="False"
ShowHeader="true"
HeaderStyle-Font-Name="arial"
HeaderStyle-Font-Bold="true"
HeaderStyle-BackColor="lightblue"
ItemStyle-Font-Name="arial"
ItemStyle-Font-Size="10pt"
AlternatingItemStyle-BackColor="pink"

CellPadding="8"
cellspacing=0
AllowPaging = "True"
PageSize = "5"
OnPageIndexChanged = "PageChange">


<PagerStyle Mode="numericpages" />



<PagerStyle backcolor="lightblue" />


<PagerStyle font-bold="true" />






<Columns>






<asp:BoundColumn
HeaderText="Product"
DataField="product" />


<asp:BoundColumn
HeaderText="Description"
DataField="description" />

<asp:BoundColumn
HeaderText="Type"
DataField="status" />


<asp:BoundColumn
HeaderText="Price"
DataField="priceactual" />





<asp:TemplateColumn>


<itemTemplate>



<table>

<tr>


<td><a href='<%# String.Format( "details.aspx?id={0}", Container.DataItem( "StoreID" ) ) %>'>More Info</a></td><td><a href='<%# String.Format( "form_to_accessdb.aspx?id={0}", Container.DataItem( "StoreID" ) ) %>'>order now</a></td>
</tr>

<tr>
<img src= "<%# Container.DataItem( "photo" )%>" width=150 height=120></td>


</tr>



</table>
</itemTemplate>
</asp:TemplateColumn>
</Columns>














</asp:DataGrid>












</form>

</body>
</html>

i will really appreciate any help



-- modified at 12:27 Wednesday 9th May, 2007
AnswerRe: code behind Pin
enjoycrack8-May-07 17:14
enjoycrack8-May-07 17:14 
AnswerRe: code behind Pin
Christian Graus8-May-07 18:07
protectorChristian Graus8-May-07 18:07 
QuestionAJAX in Existing Web applications Pin
seemamltn8-May-07 11:54
seemamltn8-May-07 11:54 
AnswerRe: AJAX in Existing Web applications Pin
Mark Greenwood8-May-07 13:24
Mark Greenwood8-May-07 13:24 
GeneralRe: AJAX in Existing Web applications Pin
seemamltn8-May-07 14:08
seemamltn8-May-07 14:08 
Questionloop to delete row from datatable Pin
raquidd228-May-07 9:08
raquidd228-May-07 9:08 
AnswerRe: loop to delete row from datatable Pin
Geo Pa8-May-07 14:23
Geo Pa8-May-07 14:23 
QuestionMy button click event runs twice in my VS 2005 - need help Pin
Slow Learner8-May-07 8:25
Slow Learner8-May-07 8:25 
AnswerRe: My button click event runs twice in my VS 2005 - need help Pin
Dave Doknjas8-May-07 13:16
Dave Doknjas8-May-07 13:16 
QuestionSet all Validation Groups at Page Load ? Pin
digsy_8-May-07 7:52
digsy_8-May-07 7:52 
QuestionCustom User Control Pin
Ridge Howison8-May-07 5:31
Ridge Howison8-May-07 5:31 
QuestionCheck all treeview nodes Pin
waddie18-May-07 4:27
waddie18-May-07 4:27 
Questionproblem with loading images in firefox using asp.net Pin
k550i8-May-07 3:53
k550i8-May-07 3:53 
AnswerRe: problem with loading images in firefox using asp.net Pin
Chris Maunder8-May-07 9:17
cofounderChris Maunder8-May-07 9:17 
QuestionIteration through stream reader Pin
samerh8-May-07 3:27
samerh8-May-07 3:27 
AnswerRe: Iteration through stream reader Pin
szukuro8-May-07 4:26
szukuro8-May-07 4:26 
QuestionCss Style Sheet Link Vs Themes / Skin / Css Pin
ToddHileHoffer8-May-07 2:10
ToddHileHoffer8-May-07 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.