mga kuya help po ulit pls...
gagawa po ako ng table ng mga employee sa CODE BEHIND... yun kasi ang approach na pinag aaralan ko ngayun. plus ayaw ko tlga masanay ng nag dadrag n drop ng mga control. As much as possible I am also avoiding writing anything on the HTML source because that will spoil my CODE-BEHIND training. so please don't reply suggesting a different approach, I just want to know whats wrong.
galing po kasi ako sa CLASSIC ASP and 2 months p lang ako nag aaral ng asp.net... I don't know kung maniniwala kayo saken pero tlgang hindi masyadong nkakatulong yung experience ko sa Classic. Maybe because lagi kong hinahanap yung substitute ng How to's ng .NET over the Classic.
anyway the my real problem as of this moment is I cant get the selectedItem.Value of a server-side Dropdownlist...
eto po ang ACTUAL code..
<%
<
</
Div_GridHolder.Style(
.InnerText =
.Style(
.Cells.Add(HeaderCELL_ID) .Cells.Add(HeaderCELL_Name) .Cells.Add(HeaderCELL_Gender) .Cells.Add(HeaderCELL_Bday) .Cells.Add(HeaderCELL_EmpStat) .Cells.Add(HeaderCELL_BLANK)
.Cells.Add(HeaderCELL_ID)
.Cells.Add(HeaderCELL_Name)
.Cells.Add(HeaderCELL_Gender)
.Cells.Add(HeaderCELL_Bday)
.Cells.Add(HeaderCELL_EmpStat)
.Cells.Add(HeaderCELL_BLANK)
.BorderWidth = 1 .BorderColor = Drawing.Color.Gray .Style(
.BorderWidth = 1
.BorderColor = Drawing.Color.Gray
.BackColor = Drawing.Color.DarkSlateGray
.Text =
.Rows.Add(HeaderROW) .CellSpacing = 0 .CellPadding = 0
.Rows.Add(HeaderROW)
.CellSpacing = 0
.CellPadding = 0
myConn.Open()
mySQL =
.Rows.Add(Body_Row)
Body_Row.Cells.Add(Body_Cell_ID)
Body_Row.Cells.Add(Body_Cell_Name)
Body_Row.Cells.Add(Body_Cell_Gender)
Body_Row.Cells.Add(Body_Cell_BDay)
Body_Row.Cells.Add(Body_Cell_Emp_Stat)
Body_Row.Cells.Add(Body_Cell_Action)
strGender =
Body_Cell_Gender.Text = strGender
myConn2.Open()
myCommand2.Parameters.Add(
.Text = myDataReader2(
myConn2.Close()
DrpLst_Action(i) =
.ID =
.Items.Add(
.Items(1).Value = 1
.Controls.Add(DrpLst_Action(i))
myConn.Close()
End
wala pong problem sa pag generate ng table at pag retrieve ng value sa dbase. ang problema tlga e yung dropdownlist value.... nde ko makuha..
onchange ng dropdownlist I tried to call the page again and pass the value of the dropdownlist sa querystring kaya lang laging yung unang item lang ang nakukuha nya.
salamat po
Ok, first off... [[snipped out because you don't want comments about a different approach i.e. postback]]
About the onchange handler, use an alert message first to see if you've wired up the event properly.
Attributes.Add("onchange", "alert(onchange triggered)")
Once you're sure the event is getting triggered, replace the text to display it with the value that you want to get from the drop down list.
[jop]
You have to set its DataValueField propertyYourDropDownList.DataTextField=FieldFromDBtoDisplay; eg "Category"YourDropDownList.DataValueField=FieldFromDB; eg "CategoryID"
kuya jop..... gumagana po yung alert
kuya ulysses.... im not trying to populate the dropdownlist i just want to trigger the onchange then get its value then maybe pass it on the querystring
DrpLst_Action(i)
DrpLst_Action(i).Attributes.Add(
SuperNoob: DrpLst_Action(i).Attributes.Add("onchange", "alert('" & DrpLst_Action(i).SelectedItem.Value & "')") <------alert always shows "0" kahit anung piliin sa dropdownlist.
Yang code na yan, tumatakbo sa server side. pag nag-execute yan, "alert(0)" and nagiging result at yun ang na-attach sa onchange.
Kailangang ma-evaluate yung value nung drop down sa client side so you have to get the value using javascript... document.getElementByName(the control's client id).value or something.
Pero hint lang ha: alam kong gusto mong matutunan kung paano gumagana yan, pero hindi yan yung typical ASP.NET programmer way ng pag-kuha ng value ng dropdownlist immediately. Normally set mo lang yung AutoPostback=true tapos kunin mo na lang yung SelectedItem sa postback handler.
using my code plus adding a ''DrpLst_Action(i).autopostback = true" results to: a postback that does not generate my employee table everytime I selectchange anyone of my dropdownlist
hi SuperNoob, just a suggestion you can use GridView to display your data in tabular format. In ASP.NET you don't need to get your hands dirty to achieve this.
SuperNoob: using my code plus adding a ''DrpLst_Action(i).autopostback = true" results to: a postback that does not generate my employee table everytime I selectchange anyone of my dropdownlist
That's easy.
Yun kasing code na nag-generate ng employee tables mo nasa loob ng If Not Postback block dun sa Page_Load. Of course, di nga madadaanan yun during postback.
Maganda ring basahin mo yung asp.net page lifecycle para maintindiha mo kung bakit nangyayari yun: http://msdn2.microsoft.com/en-us/library/ms178472.aspx
n.ocampo: hi SuperNoob, just a suggestion you can use GridView to display your data in tabular format. In ASP.NET you don't need to get your hands dirty to achieve this.
+1
In addition to the page lifecycle reading, also have a look at the asp.net quickstarts and look at the GridView samples: http://quickstarts.asp.net/QuickstartV20/aspnet/
SuperNoob: DrpLst_Action(i).Attributes.Add("onchange", "alert('hi')") <--------------working fine DrpLst_Action(i).Attributes.Add("onchange", "alert('" & DrpLst_Action(i).SelectedItem.Value & "')") <------alert always shows "0" kahit anung piliin sa dropdownlist.
DrpLst_Action(i).Attributes.Add("onchange", "alert('hi')") <--------------working fine
DrpLst_Action(i).Attributes.Add("onchange", "alert('" & DrpLst_Action(i).SelectedItem.Value & "')") <------alert always shows "0" kahit anung piliin sa dropdownlist.
Hi SuperNoob,
Just my 2 cents. On the second ..Attributes.Add, you're concatenating the selected value of your DDLB into a Javascript call. Since the above codes are executed from the server, it will always return zero . Remember, you created the DDLB on the fly and you added some items on the fly as well.
What you need to do is to get the value from the client side. I think you have to do something like...
DrpLst_Action(i).Attributes.Add("onchange", "alert(this.value)")
this will get the current selected value of the DDLB from the client side.
Regards.
wahahahaha ang galing mo kuya ninjai isa kang henyo......
hyyy kala ko mag gi-giveup na ko sa approach na 'to.
"this.value" <-- magic word
by setting the DrpLst_Action(i).autopostback = false
and adding the magic word: DrpLst_Action(i).Attributes.Add("onchange", "window.location.href=""FM_Employee_Master.aspx?SelectedValue=""+this.value")
wahahaha ang galing tlga madami na akong magagawa dito
kuya ninjai salamat ha
maraming salamat din po sa ibang nag post... sana magkaron din ng chance na ako naman ang mkatulong sa inyu. thank you po...
you're welcome :)