dba123
asked on
How to check for a row and remove it based on a commandfield click
Ok, I am not sure how I can undo my creation of rows based on the user clicking my image button.
So far, what works, is when the user clicks on the commandfield control below in my GridView, the images changes to a minus (hence collapses the gridview row to reveal it's detailed row which is newly created by my CreateRow method below)
<asp:commandfield buttontype="Image" selectimageurl="/images/pl us.gif" showselectbutton="True" />
When the user clicks the control again, the image goes back to plus. I am not sure how to:
a) capture if the user has expanded or collapsed since there is no ID attribute on a commandfield that I can grab onto to maybe do something like a check on the image to determine that
b) How to check if the CreateRow created a row before and undo it if it has...hence collapse
I am new to commandfield so bare with me. Here's the function that actually creates the row, underneath the current row that the user has selected (selected mean by clicking on the commandfield image which changes form a plus to minus icon or vice versa when clicked)
Private Sub CreateRow(ByVal table As Table, ByVal index As Integer)
Dim row As GridViewRow = New GridViewRow(-1, -1, DataControlRowType.DataRow , DataControlRowState.Normal )
Dim selectedrow As GridViewRow = SearchResults.Rows(index)
Dim StfID As Integer = SearchResults.DataKeys(ind ex).Value
row.Cells.Add(CreateColumn (StfID, index))
table.Rows.AddAt(index + 2, row)
End Sub
so how do I do the opposite? How can I check to even see if the CreateRow is even there. It's a bit tricky and not sure how to attack this
So far, what works, is when the user clicks on the commandfield control below in my GridView, the images changes to a minus (hence collapses the gridview row to reveal it's detailed row which is newly created by my CreateRow method below)
<asp:commandfield buttontype="Image" selectimageurl="/images/pl
When the user clicks the control again, the image goes back to plus. I am not sure how to:
a) capture if the user has expanded or collapsed since there is no ID attribute on a commandfield that I can grab onto to maybe do something like a check on the image to determine that
b) How to check if the CreateRow created a row before and undo it if it has...hence collapse
I am new to commandfield so bare with me. Here's the function that actually creates the row, underneath the current row that the user has selected (selected mean by clicking on the commandfield image which changes form a plus to minus icon or vice versa when clicked)
Private Sub CreateRow(ByVal table As Table, ByVal index As Integer)
Dim row As GridViewRow = New GridViewRow(-1, -1, DataControlRowType.DataRow
Dim selectedrow As GridViewRow = SearchResults.Rows(index)
Dim StfID As Integer = SearchResults.DataKeys(ind
row.Cells.Add(CreateColumn
table.Rows.AddAt(index + 2, row)
End Sub
so how do I do the opposite? How can I check to even see if the CreateRow is even there. It's a bit tricky and not sure how to attack this
ASKER
datalist?? what is that. I am using GridView for other reasons, not just this. I need paging, sorting, etc. so I choose GridView.
"datalist?? what is that "
well have a look at this link http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/default.aspx
you will see that there are a number of datacontrols provided on vs2005 asp.net of which one of them is the datalist.
However as you say, you are using the gridview for reasons like paging and sorting.
However the same concept as i outlined above can be applied. Instead of creating a new row each time, ensure that your template definition is within a templatecolum and define your own htmltable in this. (ie not using boundfields). Then onrowcommand you meerely make a div or htmlrow visible / not visible.
eg
<asp;Gridview... >
<columns>
<asp:TemplateField>
<ItemTemplate>
DEFINE YOUR TEMPLATE HERE like for example 2 divs or a htmltable
</ItemTemplate>
</colujmns>
Have a look at this link for further info on templatefield
http://msdn2.microsoft.com/en-us/library/aa479353.aspx
well have a look at this link http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/default.aspx
you will see that there are a number of datacontrols provided on vs2005 asp.net of which one of them is the datalist.
However as you say, you are using the gridview for reasons like paging and sorting.
However the same concept as i outlined above can be applied. Instead of creating a new row each time, ensure that your template definition is within a templatecolum and define your own htmltable in this. (ie not using boundfields). Then onrowcommand you meerely make a div or htmlrow visible / not visible.
eg
<asp;Gridview... >
<columns>
<asp:TemplateField>
<ItemTemplate>
DEFINE YOUR TEMPLATE HERE like for example 2 divs or a htmltable
</ItemTemplate>
</colujmns>
Have a look at this link for further info on templatefield
http://msdn2.microsoft.com/en-us/library/aa479353.aspx
ASKER
Problem is, if your html is in a templatecolum, it shows at the end, as a column of whatever row, not as a new line / new row.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm not using master/details in my gridview...
ASKER
I had no idea you could add <tr> tags inside a template. most examples don't show that. Now I see.
Just a thought.