Tamer_Ahmed Posted March 24, 2005 Posted March 24, 2005 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 Quote
kahlua001 Posted March 24, 2005 Posted March 24, 2005 specify a datakeyfield in your datalist like <asp:datalist datakeyfield="productid" ... then in your itemcommand intProductID = DataList.DataKeys(e.Item.ItemIndex) Quote
Tamer_Ahmed Posted March 25, 2005 Author Posted March 25, 2005 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 Quote
kahlua001 Posted March 25, 2005 Posted March 25, 2005 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 Quote
Tamer_Ahmed Posted March 25, 2005 Author Posted March 25, 2005 yeah this code is work fine thanks alot the problem was in e.item.itemindex thanks again Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.