944,126 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4219
  • ASP.NET RSS
Jul 4th, 2006
0

DropDownList dont send selected value to the Sub DropDown_SelectedIndexChanged

Expand Post »
I spent my whole day but I could not solve the problem. I dont have much experience in Asp.net. Please help... DropDownList dont send selected value to the Sub DropDown_SelectedIndexChanged

The Error Message is:Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 38: Protected WithEvents ItemDropDown As System.Web.UI.WebControls.DropDownList
Line 39: Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Line 40: Dim x As String= ItemDropDown.SelectedItem.Value
Line 41: label.Text= x
Line 42: End Sub



<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>



<script language="VB" Debug="true" runat="server">




Sub Page_Load(Source As Object, E As EventArgs)
If Not IsPostBack Then
bindDataGrid
End If
End Sub

Sub bindDataGrid
Dim myConn As SqlConnection
Dim mySqlAdapter As SqlDataAdapter
Dim connStr, sqlStr As String
Dim myDataSet As New Dataset
connStr="server=SELIM; uid=xxxx; pwd=xxxx; Database=TestFiles"


sqlStr="SELECT * FROM TestFiles"

myConn= New SqlConnection(connStr)
myConn.Open()
mySqlAdapter=New SqlDataAdapter(sqlStr,myConn)
mySqlAdapter.Fill(myDataSet,"Sarkilar")
FileList.DataSource=myDataSet.Tables("Sarkilar")
FileList.DataBind()
myConn.Close()
End Sub

Protected WithEvents ItemDropDown As System.Web.UI.WebControls.DropDownList
Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim x As String= ItemDropDown.SelectedItem.Value
label.Text= x
End Sub

Sub doPaging(s As Object, e As DataGridPageChangedEventArgs)
FileList.CurrentPageIndex=e.NewPageIndex
bindDataGrid
End Sub





</script>

<html>

<body bgcolor="#E5F2D8">
<form runat="server">

<p><font face="Verdana" size="1" Color="#669933" ><center>
(Mozilla Kullanicilarinin dosyayi indirdikten sonra dosyanin uzantisinida mp3 olarak degistirmeleri gerekmektedir)
</center></font></p>


<aspataGrid id="FileList" runat="server"
BorderColor="Gray"
BorderWidth="2"
CellPadding="4"

ShowHeader="true"
Align="center"
AutoGenerateColumns="false"
AllowPaging="true" PageSize="10"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center"
OnPageIndexChanged="doPaging"
>

<HeaderStyle BorderColor="white" BackColor="#669933"
ForeColor="White"
Font-Bold="True"
Font-Name="Arial"
Font-Size="9" HorizontalAlign="Center"/>

<Columns>

<asp:TemplateColumn HeaderText="Sarki Ismi">
<ItemTemplate>
<b>
<font face="arial" size="1" Color="#336633">
<%# DataBinder.Eval(Container.DataItem, "MyFileName") %>
</b>
</font>
</ItemTemplate>
</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Dosya Uzantisi">
<ItemTemplate>
<b>
<font face="arial" size="1" Color="#336633">
<%# DataBinder.Eval(Container.DataItem, "FileType") %>
</b>
</font>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Dosyayi Indir">
<ItemTemplate>
<b>
<font face="arial" size="1" Color="#336633">
<a href="indir.aspx?ID=<%# DataBinder.Eval(Container.DataItem, "ID") %>">
Indir</a>
</b>
</font>
</ItemTemplate>
</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="Puanlama">
<ItemTemplate>
<b>
<font face="arial" size="1" Color="#336633">
<%# DataBinder.Eval(Container.DataItem, "ID") %>
</b>
</font>
</ItemTemplate>
</asp:TemplateColumn>



<asp:TemplateColumn HeaderText="Oy Ver">
<ItemTemplate>
<aspropDownList ID="ItemDropDown" Runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Puan Ver"/>
<asp:ListItem Value="1" Text="1"/>
<asp:ListItem Value="2" Text="2"/>
<asp:ListItem Value="3" Text="3"/>
<asp:ListItem Value="4" Text="4"/>
<asp:ListItem Value="5" Text="5"/>
</aspropDownList>
</ItemTemplate>
</asp:TemplateColumn>



</Columns>

</aspataGrid>

</form>

<asp:label id="label" runat="server"/>
<body>
</html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
selimatmaca is offline Offline
3 posts
since Jul 2006
Jul 12th, 2006
0

Re: DropDownList dont send selected value to the Sub DropDown_SelectedIndexChanged

selam,

1-yapmak istedigin sey nedir?
2-autopostback ten haberin var mi?

kolay gelsin
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
Fenerbahce is offline Offline
62 posts
since Apr 2006
Jul 12th, 2006
0

Re: DropDownList dont send selected value to the Sub DropDown_SelectedIndexChanged

Try this instead;

ASP.NET Syntax (Toggle Plain Text)
  1. Dim x As String= ItemDropDown.SelectedValue

Oh and use [HTML][/HTML] tags around your code when posting in daniweb forums.
Last edited by hollystyles; Jul 12th, 2006 at 10:17 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Jul 13th, 2006
0

Re: DropDownList dont send selected value to the Sub DropDown_SelectedIndexChanged

selim,

if you change autopostback property of dropdownlistbox to TRUE, that will help you. and you can use Dim x As String= dropdownlistbox1.text it like this. let us know what happend.

thanks
Reputation Points: 15
Solved Threads: 0
Junior Poster in Training
Fenerbahce is offline Offline
62 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to Populate listbox2
Next Thread in ASP.NET Forum Timeline: Validation difficulties *sigh*





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC