2014年7月13日 星期日

[RESOLVED] How to handle child datalist item command in a nested datalist


Hi,


I'd like to ask  a question,


I have this code below, and i want to make action if i press the button in the child datalist for example : open colorbox to view details of the record.


but, in fact .. 


this is the code:


                GridLines="Horizontal" BorderColor="#eeeeee">

















ItemStyle-HorizontalAlign="Justify" DataSourceID="SqlDS_Crs">






<%-- CommandArgument='<%# Eval("CID") %>' ImageUrl="images/request.gif" CommandName="details" />--%>











ConnectionString="<%$ ConnectionStrings:SMET_DBConnStr %>"
SelectCommand="Admin_SP_GetCourses" SelectCommandType="StoredProcedure">

Type="Int32" />






and this is what i did in the code behind:



 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lbl_image.Text = "Training Packages"
dl_Packages.DataSource = Admin.FN_GetPackages()
dl_Packages.DataBind()
End Sub

Protected Sub dl_Packages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dl_Packages.ItemCommand
If e.CommandName = "details" Then
Dim href As String = "'Request.aspx?CID=" & e.CommandArgument & "'"
ClientScript.RegisterStartupScript(GetType(Page), "openColorbox", "openColorbox(" & href & ",630,450)", True)
End If
End Sub
Protected Sub dl_Packages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dl_Packages.ItemDataBound
CType(e.Item.FindControl("lbl_PackageName"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_Name_Ar")
CType(e.Item.FindControl("lbl_PID"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_ID")
CType(e.Item.FindControl("lblIndex"), Label).Text = e.Item.ItemIndex + 1 & ". "

'' Diaplay Courses ----------------------------------------------------------------------------

Dim PID = CInt(CType(e.Item.FindControl("lbl_PID"), Label).Text)
'CType(e.Item.FindControl("dl_Courses"), DataList).DataSource = Admin.FN_GetCourses(PID)
'CType(e.Item.FindControl("dl_Courses"), DataList).DataBind()

End Sub

the problem is, when i click on the linkbutton in datalist dl_courses, it is supposed to open anothe page in color box.


but in fact, nothing happens except the page is making refresh.



can anyone help me fixing this?



regards,







in the itemcreated event of d1_packages bind the d1_cource item command event with d1_packages item command. in that case only u will be able to finc the command of inner datalist



something like as below



Protected Sub Outer_ItemCreated(ByVal sender As Object, ByVal e As Web.UI.WebControls.DataListItemEventArgs) Handles Outer.ItemCreated

        If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then

            Dim inner As datalist= DirectCast(e.Item.FindControl("inner"), datalist)

            AddHandler inner.ItemCommand, AddressOf inner_ItemCommand

        

        End If

    End Sub



then create inner_itemcommand method and place you command code there.



hi Alaa Haider ,


 you can refer to :


 


accessing a itemdatabound handler for a nasted listview


Controlling A Nested ListView


http://forums.asp.net/t/1296888.aspx



i do like this, but i have this problem:


DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Package_ID'.


this the behind code





Protected Sub dl_Packages_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dl_Packages.ItemCreated
If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then
Dim inner As DataList = DirectCast(e.Item.FindControl("dl_Courses"), DataList)
AddHandler inner.ItemCommand, AddressOf dl_Courses_ItemCommand

End If

End Sub

Protected Sub dl_Packages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dl_Packages.ItemDataBound
CType(e.Item.FindControl("lbl_PackageName"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_Name_Ar")
CType(e.Item.FindControl("lbl_PID"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_ID")
CType(e.Item.FindControl("lblIndex"), Label).Text = e.Item.ItemIndex + 1 & ". "

'' Diaplay Courses ----------------------------------------------------------------------------
Dim PID = CInt(CType(e.Item.FindControl("lbl_PID"), Label).Text)
'CType(e.Item.FindControl("dl_Courses"), DataList).DataSource = Admin.FN_GetCourses(PID)
'CType(e.Item.FindControl("dl_Courses"), DataList).DataBind()

End Sub




Protected Sub dl_Courses_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
If e.CommandName = "details" Then
Dim href As String = "'Request.aspx?CID=" & e.CommandArgument & "'"
ClientScript.RegisterStartupScript(GetType(Page), "openColorbox", "openColorbox(" & href & ",630,450)", True)
End If
End Sub







    



i do like this, but i have this problem:


DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Package_ID'.


this the behind code



Protected Sub dl_Packages_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dl_Packages.ItemCreated If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then Dim inner As DataList = DirectCast(e.Item.FindControl("dl_Courses"), DataList) AddHandler inner.ItemCommand, AddressOf dl_Courses_ItemCommand End If End Sub Protected Sub dl_Packages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dl_Packages.ItemDataBound CType(e.Item.FindControl("lbl_PackageName"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_Name_Ar") CType(e.Item.FindControl("lbl_PID"), Label).Text = DataBinder.Eval(e.Item.DataItem, "Package_ID") CType(e.Item.FindControl("lblIndex"), Label).Text = e.Item.ItemIndex + 1 & ". " '' Diaplay Courses ---------------------------------------------------------------------------- Dim PID = CInt(CType(e.Item.FindControl("lbl_PID"), Label).Text) 'CType(e.Item.FindControl("dl_Courses"), DataList).DataSource = Admin.FN_GetCourses(PID) 'CType(e.Item.FindControl("dl_Courses"), DataList).DataBind() End Sub Protected Sub dl_Courses_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) If e.CommandName = "details" Then Dim href As String = "'Request.aspx?CID=" & e.CommandArgument & "'" ClientScript.RegisterStartupScript(GetType(Page), "openColorbox", "openColorbox(" & href & ",630,450)", True) End If End Sub


沒有留言:

張貼留言