Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

specify a datakeyfield in your datalist like

 

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

 

then in your itemcommand

 

intProductID = DataList.DataKeys(e.Item.ItemIndex)

Posted

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

Posted

Something like this..

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...