locked
render number of row of datalist by click over botton RRS feed

  • Question

  • User2041120322 posted

    hi. I have a datalist . In ItemTemplate is a botton . I want to by click over botton render number of row of datalist. 

    Wednesday, October 8, 2008 3:41 AM

Answers

  • User-1038969477 posted

    Hi persian_l ,

     

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
           Response.Write( e.Item.ItemIndex.ToString());
           Response.Write(this.DataList1.Items.Count.ToString ());
        }
      
            <asp:DataList ID="DataList1" runat="server" DataKeyField="countryid" DataSourceID="SqlDataSource1"
                OnItemCommand="DataList1_ItemCommand">
                <ItemTemplate>
                    countryid:
                    <asp:Label ID="countryidLabel" runat="server" Text='<%# Eval("countryid") %>'></asp:Label><br />
                    countryname:
                    <asp:Label ID="countrynameLabel" runat="server" Text='<%# Eval("countryname") %>'></asp:Label><br />
                    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton><br />
                </ItemTemplate>
            </asp:DataList>

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 10, 2008 2:03 AM

All replies

  • User307176038 posted

    Ok just drag a button contorl inside ItemTemplete and leave it as it is.

    Write this code for ItemCommand event of DataList as below,

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)

    {

    DataList1.SelectedIndex = e.Item.ItemIndex;

    Response.Write(DataList1.SelectedIndex.ToString());

    }

    you will get the row no. when u will click on the coresponding button

    Wednesday, October 8, 2008 7:24 AM
  • User-1038969477 posted

    Hi persian_l ,

     

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
           Response.Write( e.Item.ItemIndex.ToString());
           Response.Write(this.DataList1.Items.Count.ToString ());
        }
      
            <asp:DataList ID="DataList1" runat="server" DataKeyField="countryid" DataSourceID="SqlDataSource1"
                OnItemCommand="DataList1_ItemCommand">
                <ItemTemplate>
                    countryid:
                    <asp:Label ID="countryidLabel" runat="server" Text='<%# Eval("countryid") %>'></asp:Label><br />
                    countryname:
                    <asp:Label ID="countrynameLabel" runat="server" Text='<%# Eval("countryname") %>'></asp:Label><br />
                    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton><br />
                </ItemTemplate>
            </asp:DataList>

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 10, 2008 2:03 AM