Add Caption to GridView

Here is a tip from ASP.NET forum provided by user jcasp:
http://forums.asp.net/t/966407.aspx
 
 

<asp:GridView ID="GridView1" runat="server" Caption='<table border="1" width="100%" cellpadding="0" cellspacing="0" bgcolor="AliceBlue"><tr><td>Number of fish caught in each category (inches)</td></tr></table>’

>

 

Advertisements

Turn headertext in a GridView into a link to open a new window

In the Row_Created event of GridView, add this:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.Header)

{

foreach (TableCell cell in e.Row.Cells)

{

if (cell.Text == "Wr")

{

cell.Text =

"<a href=\"myNewpage.aspx?mycode=wr\" onclick =\"window.open(this.href, ‘popupwindow’, ‘width=600,height=270,scrollbars,resizable’); return false;\">Wr</a>";

}

}

}

}


Converting Integer to IP format

I came across this question at ASP.NET forum http://forums.asp.net/t/1423554.aspx.
User George Mastros (gmmastros) pointed the user to a post by Denis Gobo (SQLDenis) at lessthandot.com:
In this posting, SQLDenis provided two functions to convert between IP address and bigint number presentation of the IP.
 
The user was asking for an inline query to mimic the function after he read the posting.
Here is the conversion of Denis’s BigIntnumberToIp function:

–Test

declare @IP bigint
SET @IP =4278058234
--254.253.252.250

SELECT (CONVERT(VARCHAR, @IP / 16777216) + '.' 
+
        CONVERT(VARCHAR, CAST(@IP - (@IP / 16777216 * 16777216) as INT) / 65536) + '.' 
+
        CONVERT(VARCHAR, CAST((CAST(@IP - (@IP / 16777216 * 16777216) as INT) - (CAST(@IP - (@IP / 16777216 * 16777216) as int) / 65536 * 65536)) as int) / 256) + '.' 
+
        CONVERT(VARCHAR, CAST((CAST(@IP - (@IP / 16777216 * 16777216) as int) - (CAST(@IP - (@IP / 16777216 * 16777216) as int) / 65536 * 65536)) as int) - (( CAST((CAST(@IP - (@IP / 16777216 * 16777216) as int) - (CAST(@IP - (@IP / 16777216 * 16777216) as int) / 65536 * 65536)) as int) / 256) * 256)))

 

By the way, here is the orginal function by SQLDenis:
CREATE FUNCTION dbo.IntegerToIPAddress (@IP AS BIGINT)
RETURNS VARCHAR(15)
AS
BEGIN
 DECLARE @Octet1 BIGINT
 DECLARE @Octet2 TINYINT
 DECLARE @Octet3 TINYINT
 DECLARE @Octet4 TINYINT
 DECLARE @RestOfIP BIGINT
 
 SET @Octet1 = @IP / 16777216
 SET @RestOfIP = @IP – (@Octet1 * 16777216)
 SET @Octet2 = @RestOfIP / 65536
 SET @RestOfIP = @RestOfIP – (@Octet2 * 65536)
 SET @Octet3 = @RestOfIP / 256
 SET @Octet4 = @RestOfIP – (@Octet3 * 256)
 
 RETURN(CONVERT(VARCHAR, @Octet1) + ‘.’ +
        CONVERT(VARCHAR, @Octet2) + ‘.’ +
        CONVERT(VARCHAR, @Octet3) + ‘.’ +
        CONVERT(VARCHAR, @Octet4))
END