INDEXER
Displaying Google AdSense in Asp-GridView

[ad_1]

Assuming that you’ve an internet discussion board and to be able to receive max outcomes from Google AdSense (or every other advert community), you may need to place adverts in between the posts. Right here, I’ll focus on a way to put adverts in paging enabled asp:GridView management utilizing c# as a lot of the instances Asp.Web builders use Templated GridViews or Repeaters to show discussion board posts.

Okay, there are two methods: both you’ll be able to bind asp:GridView with a DataSource e.g. AccessDataSource, SQLDataSource and so forth or it’s a must to bind it manually with a DataTable, say. I’m assuming the second case i.e. The grid is solely certain to a DataTable.

1) Drag a GridView onto the shape

2) Add the next properties:

2.a) AllowPaging=”True”

2.b) AutoGenerateColumns=”False”

3) Outline occasion handlers for the next evetns:

3.a) RowDataBound

3.b) PageIndexChanging

4) and in the intervening time simply add a single column of asp:TemplateField

5) As we’re binding GridView with DataTable so fill within the desk with desired knowledge utilizing adapters and so forth.

6) Then an actual reproduction of this desk is created e.g. DataTable dt1 = dt.Clone();

7) Import all rows from the primary DataTable e.g.

foreach (DataRow dr in dt.Rows)

{

dt1.ImportRow(dr);

}

8) What I’m going to do is, add a faux row to create room for our commercial script. Now suppose you need to place your advert after the primary ‘weblog submit’. Because the ‘web page index’ of the primary web page of GridView is zero. In case of first web page we simply insert a faux row at row index one. If the DataTable is having a ‘main key test’ then initialize it with -1, say. e.g.

DataRow row2 = dt1.NewRow();

row2[“Pk_Col”] = -1; // faux worth for pk column

dt1.Rows.InsertAt(row2, index);

9) For all different GridView pages (the place PageIndex is larger than 0) calculate the row indexes and insert the faux rows.

10) Lastly bind the quickly generated desk with the grid. e.g.

grdContents.DataSource = dt1;

grdContents.DataBind();

11) Now add a WebUserControl file within the web site and place the advert script in it. This advert management will likely be loaded within the dummy rows. Within the RowDataBound occasion handler, if the RowType is DataRow and row2[“Pk_Col”] == -1 then add the AdSense management e.g. LoadControl( “AdsControl.ascx” );

That is all about it.

[ad_2]
web site index
#Displaying #Google #AdSense #AspGridView

Submit byBedewy for information askme VISIT GAHZLY

About Author

Leave a Reply

Leave a Reply