asp.net 中的資料繫結

ASPX

<asp:DataList runat="server" CssClass="sample" RepeatLayout="Flow" ID="dlsamplecontent" RepeatDirection="Vertical" OnItemCommand="dlsamplecontent_ItemCommand">
       <ItemStyle CssClass="tdContainer" />
           <ItemTemplate>
             //you code 
                    </ItemTemplate>
                </asp:DataList>

Aspx.cs

public void GetSamplingContentType()
    {
        try
        {
            ErrorLogger.gstrClientMethodName = this.GetType().FullName + "_" + System.Reflection.MethodBase.GetCurrentMethod().Name + " : ";

         DataTable dt = new DataTable();
            dlsamplecontent.DataSource = dt;
            dlsamplecontent.DataBind();

        }
        catch (Exception ex)
        {
            ErrorLogger.ClientErrorLogger(ex);
        }
    }

專案命令和使用 Command 引數檢索 Id

 protected void dlsamplecontent_ItemCommand(object source, DataListCommandEventArgs e)
    {

        try
        {
            int BlogId = Convert.ToInt32(e.CommandArgument.ToString());
            if (e.CommandName == "SampleName")
            {
               //your code 

            }
        }
        catch (Exception ex)
        {
            ErrorLogger.ClientErrorLogger(ex);
        }
    }