davearia Posted July 6, 2007 Posted July 6, 2007 Hi All, I have web page that has a table, in the table there is a repeater. Two of the columns in the repeater have XML in them that can be quite big. What I wanted to do is when the repeater shows this table is have a button/link saying view xml for each row in these two columns. If the user clicks the link, that particular field for that row/column would show its XML. It would be nice to use an AJAX control, I was looking at: http://ajax.asp.net/ajaxtoolkit/CollapsiblePanel/CollapsiblePanel.aspx. But I am not sure if this would be the best solution. If anyone has any ideas please reply. I hope this post makes sense. Cheers, Dave. Quote
davearia Posted July 10, 2007 Author Posted July 10, 2007 Hi, I managed it in the end. What I did was in the repeater build up a literal for the divs etc and add the javascript needed to make this client side event happen. Here is a snippet of it: 'Find and populate response XML column. Dim litResponseXML As Literal = CType(e.Item.FindControl("litResponseXML"), Literal) If GoogleRow.Item("ResponseData") IsNot System.DBNull.Value Then Try 'Dynamically build the content for the response XML column. Dim responseXML As String = GoogleRow.Item("ResponseData").ToString Dim sb As New StringBuilder Dim divShowHideResponse As String = "divShowHideResponse" & rowCounter.ToString Dim divShowHideResponseButton As String = "divShowHideResponseButton" & rowCounter.ToString Dim litButtonText As String = "litShowHideResponseButtonText" & rowCounter.ToString sb.Append("<div>") sb.Append(Environment.NewLine) sb.Append("<div id=""" & divShowHideResponse & """ style=""height: 75px; padding: 1px; display: none"">") sb.Append(Environment.NewLine) sb.Append("<textarea name=""txtResponseXML"" rows=""3"" cols=""20"" id=""txtResponseXML"" readonly=""readonly"" style=""height:70px;width:500px;background-color:white"">" & responseXML & "</textarea>") sb.Append(Environment.NewLine) sb.Append("</div>") sb.Append(Environment.NewLine) sb.Append("<div id=""" & divShowHideResponseButton & """ runat=""server"" style=""background-color:#cc0033; color: white; font-weight: bold; padding: 1px; cursor: pointer"" onclick=""toggle('" & divShowHideResponse & "','" & divShowHideResponseButton & "')""><asp:Literal runat=""server"" ID=""" & litButtonText & """>View XML</asp:Literal></div>") sb.Append(Environment.NewLine) sb.Append("</div>") litResponseXML.Text = sb.ToString Catch ex As Exception litResponseXML.Text = " " End Try Else litResponseXML.Text = " " End If Here is the mothod which I regstered to the page Private Sub CreateShowHideJavaScript() Dim sb As New StringBuilder sb.Append("<script type=""text/javascript"">") sb.Append(Environment.NewLine) sb.Append("function toggle(divXML,divButton)") sb.Append(Environment.NewLine) sb.Append("{") sb.Append(Environment.NewLine) sb.Append("var oDiv = document.getElementById(divXML);") sb.Append(Environment.NewLine) sb.Append("var oDiv2 = document.getElementById(divButton);") sb.Append(Environment.NewLine) sb.Append("oDiv.style.display = (oDiv.style.display == ""none"") ? ""block"" : ""none"";") sb.Append(Environment.NewLine) '1. This works for firefox: sb.Append("oDiv2.textContent = (oDiv.style.display == ""none"") ? ""View XML"" : ""Hide XML"";") sb.Append(Environment.NewLine) '2. This works for I.E. sb.Append("oDiv2.innerText = (oDiv.style.display == ""none"") ? ""View XML"" : ""Hide XML"";") sb.Append(Environment.NewLine) sb.Append("oDiv2.style.backgroundColor = (oDiv.style.display == ""none"") ? ""rgb(204, 0, 51)"" : ""green"";") sb.Append(Environment.NewLine) sb.Append("}") sb.Append(Environment.NewLine) sb.Append("</script>") Page.ClientScript.RegisterStartupScript(Me.GetType(), "showHide", sb.ToString()) End Sub I am sure there are more slicker ways of doing this. But it works well, as I am not the best at javascript it is a mile stone for me. Cheers, Dave. 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.