hey guys i have a web page involving a listview and every supitem has a button !!
deal is tht wen i click on the button i need to get the INDEX of the listview subitem in which the button was clicked!!! please help me through this :)
Protected Sub button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim btn As Button = sender
dim i as integer
i= ? 'INDEX OF LISTVIEW ITEM'
Dim tb As TextBox
tb = New TextBox
tb = ListView1.Items.Item(b).FindControl("textbox2")
tb.Visible = True
here "B" is the index!!! so when i click the button the textbox in listview should be visible!!!
Ok, so I see your VB code there (and I'm sorry but I don't know VB much, I'm a C# guy) but did you read through any of the search results linked in my previous post? Because at least 2-3 of the ones on page 1 of that search should be able to solve your issue for you :)
Again, not being a VB coder I can't really help you past that. Good luck though.
dude can u tell me how to do it in c# so tht atleast ill get the logic!!! i mean theres a button and a textbox in every listview items!! so when i click on the button i should be able to make the text box visible!! so can ya guide in C# :)
It's getting late here, I'm tired, and I've never tried this before...
I think this would work in C# to do what you're looking for assuming I got your variables correct (like textBox2 and such):
private void btnEquals_Click(object sender, EventArgs e)
Button btn = (Button)(sender); // declare variable btn as event sender
int itemNum = -1; // declare int itemNum with init value outside of listView range
for (int a = 0; a < listView1.Items.Count; a++) //Loop items in listView
for (int b = 0; b < listView1.Items[a].SubItems.Count; b++) //Loop subitems in listView
if (listView1.Items[a].SubItems[b].Name == btn.Name) // check for button within subitems
itemNum = a;
TextBox tb = new TextBox();
tb.Text = listView1.Items[itemNum].SubItems["textBox2"].ToString();
tb.Visible = true;
No guarantees, but I think this will work. And you might be able to reverse-engineer it to VB (for VB the statement "Button btn = (Button)(sender);" would likely evaluate to "Dim btn as Button = DirectCast(sender, Button)")
ok, I was assuming that the subitem was the button based on your originally suplied code snippet.
Basically I was looking at it as listView -> items(rows) -> subItems(components within the row) and so the code sample I put together for you gives you the row index based on the fact that the row contains the subItem of the button.
The logic for the looping still stands if you need to go down further in levels but I'm not sure how far down the levels go for what you're trying to do.
I just double checked, the furthest you can drill-down on a listView is:
listView -> Items -> subItems
Based on that, I'm going to have to stick with what I said before, my first loop checks each row (items) and my second loop checks each item in that row (subItems) and determines if one of those subItems is the button that called the click event. Once it finds the right button it reports back the row index (Items) and attempts to populate the outside textBox with the values of an item called "textBox2" within that row.
If that's not what you're looking for then unfortunately I'm unable to help cus even getting that much for you involved going beyond what I usually use a listView for (as I've never really gone to the level of subItems before).