I have an UpdatePanel containing a ListBox. Whenever I change selection on from a DropDown I want the list to get updated via an UpdatePanel. However this is not working.
This is my code so far:
Protected Sub drpDepartments_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpDepartments.SelectedIndexChanged
Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
Dim deptComm As String = "SELECT department_id FROM departments WHERE department_name = #DepartmentName"
Dim deptSQL As New SqlCommand
Dim dr As SqlDataReader = deptSQL.ExecuteReader()
deptSQL = New SqlCommand(deptComm, conn)
deptSQL.Parameters.AddWithValue("#DepartmentName", drpDepartments.SelectedItem.Text)
dr.Read()
If dr.HasRows Then
Dim department_id As Integer = Convert.ToInt32(dr("department_id"))
Session("DepartmentID") = department_id
End If
dr.Close()
conn.Close()
ASP
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ListBox ID="lstDeptMembers" runat="server" DataSourceID="SqlDataSource4" DataTextField="name" DataValueField="name" Height="176px" Width="204px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpDepartments" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT * FROM users u
INNER JOIN
(
Select x.user_id as userid,x.department_id,y.department_name
from user_Department x
inner join departments y
on x.department_id=y.department_id WHERE x.department_id=#parameter
)
f on u.user_id= f.userid">
<SelectParameters>
<asp:SessionParameter Name="parameter" SessionField="DepartmentID" />
</SelectParameters>
</asp:SqlDataSource>
DropDownList:
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [department_name] FROM [departments]"></asp:SqlDataSource>
Screenshot:
How can I make it that the ListBox updates whenever a new selection is clicked from the DropDown ?
EDIT: Code for the table that contains the ListBox etc.. :
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [department_name] FROM [departments]"></asp:SqlDataSource>
<br />
<br />
<table style="width:100%;">
<tr>
<td style="width: 221px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ListBox ID="lstDeptMembers" runat="server" DataSourceID="SqlDataSource4" DataTextField="name" DataValueField="name" Height="176px" Width="204px"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpDepartments" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT * FROM users u
INNER JOIN
(
Select x.user_id as userid,x.department_id,y.department_name
from user_Department x
inner join departments y
on x.department_id=y.department_id WHERE x.department_id=#parameter
)
f on u.user_id= f.userid">
<SelectParameters>
<asp:SessionParameter Name="parameter" SessionField="DepartmentID" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td style="width: 398px">
<asp:TextBox ID="txtuserSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearchDeptUser" runat="server" Text="Search" />
<br />
<asp:Label ID="lblAddDeptUser" runat="server" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td >
<asp:Button ID="btnRmvDeptMem" runat="server" Text="Remove" />
</td>
<td>
<asp:Button ID="btnAddDeptUser" runat="server" Text="Add" />
</td>
</tr>
</table>
Full code for Departments.aspx
If you want to update the UpdatePanel immediately when the user selects an item in the DropDownList you have to set it's AutoPostBack property to "True"(default is false):
<asp:DropDownList ID="drpDepartments" runat="server" DataSourceID="SqlDataSource3"
AutoPostack="True" DataTextField="department_name" DataValueField="department_name">
</asp:DropDownList>
try this...
Change this
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
with
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
Related
Dear all i have the following dropdownlist which is inside an update panel inside a repeater.
<asp:Repeater OnItemDataBound="rprProperties_ItemDataBound" ID="rprProperties" runat="server">
<ItemTemplate>
<div class="mb-2">
<asp:Label style="width : 100px;float:left;" ID="Label1" runat="server" Text='<%# Container.DataItem("name") %>'></asp:Label>
<asp:Label style="width : 100px;float:left;" ID="propID" runat="server" Text='<%# Container.DataItem("id") %>' Visible="false"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ClientIDMode="AutoID" AutoPostBack="true" OnSelectedIndexChanged="ddlProperty_SelectedIndexChanged" style="width:100px" CssClass="filter-dropdown bg-light" DataValueField="id" DataTextField="name" ID='ddlProperty' runat="server"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:Repeater>
i'm populating the ddl with this code in the ItemDataBound event of the repeater.
Dim propID As Label = TryCast(e.Item.FindControl("propID"), Label)
Dim ddl As DropDownList = TryCast(e.Item.FindControl("ddlProperty"), DropDownList)
Dim varDbconn As New SqlConnection(ConfigurationManager.ConnectionStrings("shopCS").ToString)
Dim varDbcomm As SqlCommand
Dim varDbRead As SqlDataReader
varDbconn.Open()
varDbcomm = New SqlCommand("exec spShowItemPropValues #property,#id,#lang ", varDbconn)
varDbcomm.Parameters.AddWithValue("#property", SqlDbType.Int).Value = propID.Text
varDbcomm.Parameters.AddWithValue("#id", SqlDbType.Int).Value = Request.QueryString("id")
varDbcomm.Parameters.AddWithValue("#lang", SqlDbType.NVarChar).Value = Session("lang")
varDbRead = varDbcomm.ExecuteReader()
Dim varDt As New DataTable
varDt.Load(varDbRead)
ddl.DataSource = varDt
ddl.DataBind()
varDbcomm.Dispose()
varDbRead.Close()
varDbconn.Close()
when i select a value, the dropdownlist resets to the first item in the dropdownlist instead of keeping the selected value.
i want to retain that value.
thanks.
You forgot to add the AsyncPostBackTrigger. Put it before </UpdatePanel>
<asp:Repeater OnItemDataBound="rprProperties_ItemDataBound" ID="rprProperties" runat="server">
<ItemTemplate>
<div class="mb-2">
<asp:Label style="width : 100px;float:left;" ID="Label1" runat="server" Text='<%# Container.DataItem("name") %>'></asp:Label>
<asp:Label style="width : 100px;float:left;" ID="propID" runat="server" Text='<%# Container.DataItem("id") %>' Visible="false"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ClientIDMode="AutoID" AutoPostBack="true" OnSelectedIndexChanged="ddlProperty_SelectedIndexChanged" style="width:100px" CssClass="filter-dropdown bg-light" DataValueField="id" DataTextField="name" ID='ddlProperty' runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProperty" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:Repeater>
I have several forms, each with their own DDL, that I'm using inside a page. I have them in different forms because I need different data sources for each DDL. When I press the Submit button, it gives me an error that it can't find the control "ddlCategory". I assume it is because it is in a different form. Here is the markup:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<br />
<asp:FormView ID="FormView2" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource2" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView3" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource3" DefaultMode="Insert" >
<InsertItemTemplate>
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
Also, if there is a way to do it inside one formview control, I'd like to know that too.
Did it this way:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM [ORGANIZATIONS]"/>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ATTY_ID, NAME & ' ' & INITIAL & ' ' & LASTNAME AS Expr1 FROM ATTORNEYS ORDER BY NAME & INITIAL & ' ' & LASTNAME">
</asp:AccessDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert" >
<InsertItemTemplate>
Select a Category:<br />
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True"
DataSourceID="AccessDataSource1" DataTextField="ORG_NAME"
DataValueField="ID">
</asp:DropDownList>
<br />
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT ID,SectionName FROM ORG_SECTIONS WHERE OrgID=#OrgID ">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategory"
PropertyName="SelectedValue"
Name="ID" Type="String"
DefaultValue="" />
</SelectParameters>
</asp:AccessDataSource>
Select an Organization:<br />
<asp:DropDownList ID="ddlOrg" runat="server"
DataSourceID="AccessDataSource2" DataTextField="SectionName"
DataValueField="ID">
</asp:DropDownList>
<br />
Select an Attorney:<br />
<asp:DropDownList ID="ddlAtty" runat="server"
DataSourceID="AccessDataSource3" DataTextField="Expr1" DataValueField="ATTY_ID">
</asp:DropDownList>
</InsertItemTemplate>
</asp:FormView>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="AddRec" />
And the code behind:
protected void AddRec(object sender, EventArgs e)
{
DropDownList ddlCategory = (DropDownList)FormView1.FindControl("ddlCategory");
DropDownList ddlOrg = (DropDownList)FormView1.FindControl("ddlOrg");
DropDownList ddlAtty = (DropDownList)FormView1.FindControl("ddlAtty");
string constr = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\webvideos.mdb;";
string cmdstr = "INSERT INTO [Org_Sec_Atty] ([OrgID], [SecID], [Atty_ID]) VALUES (?, ?, ?)";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand com = new OleDbCommand(cmdstr, con);
con.Open();
com.Parameters.AddWithValue("#OrgID", ddlCategory.SelectedValue);
com.Parameters.AddWithValue("#SecID", ddlOrg.SelectedValue);
com.Parameters.AddWithValue("#AttyID", ddlAtty.SelectedValue);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("ManageProfAffs.aspx");
}
And done.
This codes works great except for getting the post values... I have the select hard coded now, but I want to obtain the values from the form post and populate from that... I hope there's a way to do this using inline asp.net (vb.net)...
<%# Page language="VB" %>
<!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 id="Head1" runat="server">
<title>ListView Templates Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Modifying Quantities for: </h3>
<asp:SqlDataSource ID="Sql" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT [name],[id] FROM [markets]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="yearSQLDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT distinct(year) as year from transactions order by year asc">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT shortname, id from products order by name asc">
</asp:SqlDataSource>
<asp:Label ID="market" runat="server" Text="Market:" />
<asp:DropDownList ID="markets" runat="server"
DataSourceID="Sql" DataTextField="name" DataValueField="id" >
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="Products:" />
<asp:DropDownList ID="products" runat="server"
DataSourceID="SqlDataSource1" DataTextField="shortname" DataValueField="id" >
</asp:DropDownList>
<!--TODO use databind in Page_Load to fill from SQL and then use distributor ID instead of name to match-->
<asp:Label ID="year" runat="server" Text="Year:" />
<asp:DropDownList ID="years" runat="server"
DataSourceID="yearSQLDataSource" DataTextField="year" DataValueField="year" >
</asp:DropDownList>
<asp:button ID="Button1" runat="server" text="Submit" postbackurl="fourrosesformDataList3.aspx" />
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="id"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">Action</th>
<th id="Th2" runat="server">Month</th>
<th id="Th3" runat="server">Quantity</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="Label1" runat="Server" Text='<%#Eval("MonthName") %>' />
</td>
<td>
<asp:Label DataTextField = "standardcase" ID="standardcase" runat="Server" Text='<%#Eval("standardcase") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr style="background-color: #ADD8E6">
<td>
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="Label3" runat="Server" Text='<%#Eval("MonthName") %>' />
</td>
<td>
<asp:TextBox ID="standardcase" DataTextField = "standardcase" runat="server" Text='<%# Bind("standardcase") %>'
MaxLength="50" /><br />
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT standardcase, shortname, datename(month,dateadd(month, t.month - 1, 0)) as MonthName, t.id as id
from transactions t, products p where p.id=t.product_id and year = 2009 and market_id = 1 and product_id = 1"
UpdateCommand="UPDATE transactions
SET standardcase = #standardcase
WHERE id = #id"
>
</asp:SqlDataSource>
</form>
</body>
</html>
so instead of "where p.id=t.product_id and year = 2009 and market_id = 1 and product_id = 1"
I want to do "where p.id=t.product_id and year = #postYear and market_id = #postMarket and product_id = #postProduct" from the form at the top of the page.
Use the selectparameters tag of asp:sqldatasource. Exactly how you do it depends on whether you are getting the value from a control on the current page.
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand="SELECT standardcase, shortname, datename(month,dateadd(month, t.month - 1, 0)) as MonthName, t.id as id
from transactions t, products p where p.id=t.product_id and year = #year and market_id = #market and product_id = #product">
<selectparameters>
<asp:controlparameter name="year" controlid="DropDownList1" propertyname="SelectedValue"/>
<asp:controlparameter name="market" controlid="DropDownList1" propertyname="SelectedValue"/>
<asp:controlparameter name="products" controlid="DropDownList1" propertyname="SelectedValue"/>
</selectparameters>
</asp:sqldatasource>
Be aware that this does leave a vulnerability, see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.selectparameters(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 for more details.
The formparamter property worked for me:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formparameter.formfield(v=vs.110).aspx
I may look at the controlparameter too... T
I have problem in my web
I have page contain 3 dropdown lists in update panel, every dropdown list has autopost back property, but autopost does not run.
My page is
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DrReg" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="Drcity" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="DrZone" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<table style="width: 100%;" dir="rtl">
<tr>
<td>
المنطقة
</td>
<td>
<asp:DropDownList ID="DrReg" runat="server" AutoPostBack="True" >
</asp:DropDownList>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
</tr>
<tr>
<td>
المدينة
</td>
<td>
<asp:DropDownList ID="Drcity" runat="server" AutoPostBack="True">
</asp:DropDownList>
<%-- <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>--%>
<asp:SqlDataSource ID="OrgSQl" runat="server"
ConnectionString="<%$ ConnectionStrings:ymConnectionString %>"
SelectCommand="SELECT [GovID], [Gov_Title] FROM [Gov] WHERE (([Region_Id] = #Region_Id) AND ([FalgeDel] = #FalgeDel))">
<SelectParameters>
<asp:ControlParameter ControlID="DrReg" Name="Region_Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter DefaultValue="False" Name="FalgeDel" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
الحي
</td>
<td>
<asp:DropDownList ID="DrZone" class="inputbox multiple" runat="server" AppendDataBoundItems="True"
Width="120px">
<asp:ListItem Value="0">الكل</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="Zonsql" runat="server"
ConnectionString="<%$ ConnectionStrings:ymConnectionString %>"
SelectCommand="SELECT * FROM [Zone] WHERE (([City_ID] = #City_ID) AND ([FlagDel] = #FlagDel))">
<SelectParameters>
<asp:ControlParameter ControlID="Drcity" Name="City_ID"
PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter DefaultValue="False" Name="FlagDel" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
</td>
<td align="center">
<asp:LinkButton ID="SearchBtnok" class="button" runat="server"
ValidationGroup="searchysf">ابحث</asp:LinkButton>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
the code is
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' btnCloseBrowser.Attributes.Add("onclick", "self.close()")
If Not Page.IsPostBack Then
obj.Bind(Me.DrReg, " countrt where FlageDel=0 ", "ALL")
obj.Bind(Me.Drcity, " city WHERE FalgeDel=0 and Country_Id=" & DrReg.SelectedValue, "All")
obj.Bind(Me.DrZone, " Zone WHERE FlagDel=0 and City_ID =" & Drcity.SelectedValue, "اختر")
End If
End Sub
Protected Sub DrReg_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DrReg.SelectedIndexChanged
obj.Bind(Me.Drcity, " city WHERE FalgeDel=0 and Country_Id=" & DrReg.SelectedValue, "All")
obj.Bind(Me.DrZone, " Zone WHERE FlagDel=0 and City_ID =" & Drcity.SelectedValue, "All")
End Sub
Protected Sub Drcity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Drcity.SelectedIndexChanged
obj.begintrans()
obj.Bind(Me.DrZone, " Zone WHERE FlagDel=0 and City_ID =" & Drcity.SelectedValue, "All")
obj.comitttrans()
End Sub
You have to set AutoPostback="True" on each of your dropdownlists. The Triggers section doesn't make them post back, it only handles the events that already occur.
After editing some fields, clicking on Update doesn't show the new values. I have tried two ways to retrieve the new values as you can see from this shortened version of the ItemUpdating event (and both return the old ones) :-
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim txtPassword As TextBox = CType(DetailsView1.Rows(1).Cells(1).FindControl("txtPassword"), TextBox)
Struct_Student.password = txtPassword.Text
Dim PasswordValue As String = e.NewValues("password").ToString()
Struct_Student.password = PasswordValue
End Sub
Here is a shortened version of the aspx :-
<asp:Content ID="Content1" ContentPlaceHolderID="cpMainContent" Runat="Server">
<div id="Controls">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1"
runat="server"
AutoGenerateRows="False"
DataKeyNames="student_id" DataSourceID="SqlDataSource1"
ForeColor="Blue"
BackColor="#FFF7E6"
AutoPostBack="True"
AutoGenerateEditButton = True
AutoGenerateInsertButton = True
OnModeChanging="StudentDetailView_ModeChanging"
Height=163px
Width=327px
style="left: 400px; top: 1px; position: absolute;">
<Fields>
<asp:TemplateField
HeaderText="Password">
<EditItemTemplate>
<asp:TextBox
id="txtPassword"
Text = '<%# Bind ("password") %>'
runat = "server" />
<asp:RequiredFieldValidator
ID = "reqPassword"
ControlToValidate = "txtPassword"
Text = "(required)"
Display = "Dynamic"
runat = "server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label
id="PasswordLabel"
runat="server"
Text = '<%# Eval("password") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField
datafield="emailaddress"
headertext="Email address"
SortExpression="emailaddress"
/>
</Fields>
</asp:DetailsView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:FCLManager %>" ProviderName="MySql.Data.MySqlClient"
SelectCommand="Select * from tblstudentinfo WHERE centre_id = #CentreID and fullname = #FullName"
<SelectParameters>
<asp:Parameter Name="CentreID" Type="Int16" DefaultValue="0" />
<asp:Parameter Name="FullName" Type="String" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div> <%--Controls div--%>
</asp:Content>