Link to home
Start Free TrialLog in
Avatar of laks_win
laks_winFlag for India

asked on

Generating Serial Number in DataList/Repeater template column!!

Hi Experts,

Please help me on these questions!!
1. How to generate serial numbers in datalist/repeater template columns. Ex. 1,2,3....

2. How to code to open a popup window in the Hyperlink column, by passing the "ID" value from databinder value.

thanx in advance
Laks.R
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,
   
1.  When every time a row is binding "OnItemCommand" event is fired. So add a template column for serial number.  Find for that control in column one. Then u assign a running serial number to it.

2. Try the below one.

<asp:HyperLink Target=_blank NavigateUrl="yourpage.aspx?ID=<%# DataBinder.Eval (Container.DataItem, "<place the COLUMN NAME U WANT TO PASS> ") %>" ></asp:HyperLink>

-Aaron
Avatar of laks_win

ASKER

Tq Mr.apeter.

1. If u provide the exact sample, it will be really helpful.
2. I need to open the popup with the fixed HEIGHT, WIDTH and RESIZABLE=no

Expecting ur erlier reply.

With Thanx
Laks.R
Hi,
   I'm giving in C# syntax.  Please convert to VB.NET if ur using. Please let me know if anything else.

1. For Serial No.

   1.1 In ASPX file. Place this code.

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 88px; POSITION: absolute; TOP: 208px" runat="server" Width="216px" Height="120px">
<Columns >
      <asp:TemplateColumn HeaderText="SL.No" >
            <ItemTemplate>
                  <asp:Label ID="sl" Runat=server></asp:Label>
            ItemTemplate>
      </asp:TemplateColumn>
</Columns>
</asp:DataGrid>

2. Put the below code in Code behind method -------- InitializeComponent()
    this.DataGrid1.ItemDataBound += new DataGridItemEventHandler(this.Item_bound);


3. Add the below new mothod and member(i) in code behind.

Int32 i = 0;
void Item_bound(Object sender, DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==  
                                                                         ListItemType.AlternatingItem))
      e.Item.Cells[0].Text = i.ToString();

      i++;
}

4. Add below method in Page Load(), to populate dummy value in DataGrid.

ArrayList list = new ArrayList();
list.Add("A");
list.Add("B");
list.Add("C");
DataGrid1.DataSource = list;
DataGrid1.DataBind();

-Aaron
   
Thank u Mr.apeter for ur suggession.

My question is, to put the serial numbers in DATALIST/REPEATER controls. Yes, i need to put them in a template column as a first column.

expecting ur favourable reply.

thanx and regards
Laks.R
ASKER CERTIFIED SOLUTION
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi apeter,

Thank u for ur gr8 suggession.

Its working ok in VS.et 2005.
But in VS.net 2003, the last row number is displayed in all rows (ie). if the record count is 5, then 5 is displayed in all rows.

I am in doubt that, after processing the "ItemDatabound" method, it is rendering the data!!!

pls try the final solution!!!

regards
Laks.R
Hi,
   Could you please give me your code. So that i can see where it is going wrong. See that ur using the same variable for Serial Number and for row count also.

-Aaron
Hi apeter

I am extremely sorry for the late reply.
The mistake is from my side. Yes, i tried two <ItemTemplate> columns in a Datalist/Repeater without care and tried..tried....!!.

After making it to single, it works well.
Thank u for ur kind suggession and replies.

If possible, pls answer me to the second Qtn.

2. How to code to open a popup window in the Hyperlink column, by passing the "ID" value from databinder value.

Thanx and Regards
Laks.R