datalist problem

Tamer_Ahmed

Centurion
Joined
Dec 20, 2003
Messages
159
Location
Egypt
hi all,
i get a list of products and bind it to a datalist
and there's a Compare button on the header template
and there's a checkbox in every row
when the user press compare
i want to get the product id which is selected by user
i don't have problem in wirting the code in the itemCommand the problem here
i don't know how to get the product id

this is my code
If e.CommandName = "Compare" Then
Dim str As String
For Each anitem In DataList2.Items
isChecked = CType(anitem.FindControl("chk"), CheckBox).Checked
If isChecked = True Then
i don't know what to write here
End If
Next

End If
plz help me
 
specify a datakeyfield in your datalist like

<asp:datalist datakeyfield="productid" ...

then in your itemcommand

intProductID = DataList.DataKeys(e.Item.ItemIndex)
 
hey
ur solution will work only if my datalist postback in every selection
and this is not what happen here
i have a datalist multiple checkbox
i want to get the id of the item that have a checked checkbox
my datalist wil postback only when the user click the button and the itemindex will be -1
hope u have another solution for me
 
Something like this..

Code:
Private Sub Button1_Click(s as object, e as event args) handles Button1.Click
   Dim item As DataGridItem
   Dim mycheckbox as checkbox
   Dim intID As Integer
   For each item in Datagrid1.Items
      mycheckbox = item.findcontrol("CheckBox1")
      intID = DataGrid1.Datakeys(item.itemindex)
      If mycheckbox.checked then
         ..your code
      end if
   Next
End Sub
 
Back
Top