<asp:GridView ID=”GridView1″ runat=”server” DataKeyNames=”id” DataSourceID=”SqlDataSource1″>
<Columns>
<asp:TemplateField ShowHeader=”False”>
<ItemTemplate>
<asp:LinkButton ID=”LinkButton1″ runat=”server” CausesValidation=”False” CommandName=”Delete”
OnClientClick=’return confirm(“Are you sure you want to delete this entry?”);’
Text=”Delete” />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
http://www.pluralsight.com/community/blogs/fritz/archive/2006/03/22/20514.aspx

Get parameters

13 October 2009

<a href=”prodotto.php?cod=a7&cat=2″>

Add a script in a webpage

13 October 2009

//file .cs

Literal1.Text = “<script>AlertOk(“+num+”);</script>”;

//file html
<script language=”javascript”>
function AlertOk(Par1) {
alert(‘Dati caricati ‘+Par1);
}
</script>

<asp:TemplateField HeaderText=”View”>
<ItemTemplate>
<asp:HyperLink ID=”HyperLink1″ runat=”server” Target=”_blank” NavigateUrl=’<%#”VisualizzaPubblicazione.aspx?ID_PUB=”+ Eval(“ID_PUB”)%>’> View </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>

Check the IP address

13 October 2009

Controllo IP

If Left(Request.ServerVariables(“REMOTE_ADDR”),10)<>”192.168.0.” then
Response.Redirect(“http://www.google.it”)
End If

Response.BufferOutput = False
Response.ContentType = “application/vnd.ms-excel”
Response.AppendHeader(“content-disposition”, “inline; filename=Esporta.xsl”)
*****************istruzioni
Response.Flush()
Response.End()

Absolute path to images

13 October 2009

<%= Request.ApplicationPath %>

<a href=”<%=Request.ApplicationPath%>/info/Page.aspx”>Link to Page</a>

I add a button to GridView with a specific command:

<asp:Button ID=”Button1″ runat=”server” Text=”Conferma” CommandName=”Conferma” CommandArgument=”<%#((GridViewRow) Container).RowIndex %>”/>

protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == “Conferma”)
{
// Retrieve the row index stored in the
// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];

// Add code here to add the item to the shopping cart.
}

}

After I update the table with the command

DataTable.Bind()

Getting last id

13 October 2009

If you want put last id (a key number) from a table, you can use this code:
String query2=”SELECT @@IDENTITY as IDrestituito”;
OleDbCommand cmd2 = new OleDbCommand(query2, con);
String stringRet=cmd2.ExecuteScalar().ToString();
Int32 ret = Int32.Parse(stringRet);
return ret;

Number of rows in GridView

12 October 2009

<asp:TemplateField HeaderText="N.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>

Follow

Get every new post delivered to your Inbox.