掌握/详细信息ASP.NET C#DataGrid?

时间:2015-08-07 03:56:44

标签: c# asp.net datagrid

我想用DataGrid而不是GridView或其他任何东西显示数据Master / Details stype。目前我必须手动输入一个下拉列表。那么每当我们点击Master DataGrid中的一个主项目然后它链接到Details DataGird时,如何自动完成它,如下所示: Master/Details DataGrid

    private void BindGridMaster()
    {
        grdReceivedNote.DataSource = ReceivedNoteService.ReceivedNote_GetByAll();
        grdReceivedNote.DataBind();
        if (grdReceivedNote.PageCount <= 1)
        {
            grdReceivedNote.PagerStyle.Visible = false;
        }
        else
        {
            grdReceivedNote.PagerStyle.Visible = true;
        }
    }
    private void BindGridDetails()
    {
        grdReceivedNoteDetails.DataSource = RevNoteDetailsService.RevNoteDetails_GetByAll();
        grdReceivedNoteDetails.DataBind();
        if (grdReceivedNoteDetails.PageCount <= 1)
        {
            grdReceivedNoteDetails.PagerStyle.Visible = false;
        }
        else
        {
            grdReceivedNoteDetails.PagerStyle.Visible = true;
        }
    }
    protected void grdReceivedNote_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        ListItemType itemType = e.Item.ItemType;
        if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))
        {
             if (itemType == ListItemType.Header)
             {
                 object checkBox = e.Item.FindControl("chkSelectAll");
                 if ((checkBox != null))
                 {
                      ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
                 }
            }
            else
            {
                 string tableRowId = grdReceivedNote.ClientID + "_row" + e.Item.ItemIndex.ToString();
                 e.Item.Attributes.Add("id", tableRowId);
                 object checkBox = e.Item.FindControl("chkSelect");
                 if ((checkBox != null))
                 {
                      e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
                      e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex.ToString() + ")");
                      ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex.ToString() + ")");
                  }
            }
       }
   }
   protected void grdReceivedNoteDetails_ItemDataBound(object sender, DataGridItemEventArgs e)
   {
       ListItemType itemType = e.Item.ItemType;
       if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))
       {
            if (itemType == ListItemType.Header)
            {
                object checkBox = e.Item.FindControl("chkSelectAll");
                if ((checkBox != null))
                {
                    ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
                }
           }
           else
           {
                string tableRowId = grdReceivedNote.ClientID + "_row" + e.Item.ItemIndex.ToString();
                e.Item.Attributes.Add("id", tableRowId);
                object checkBox = e.Item.FindControl("chkSelect");
                if ((checkBox != null))
                {
                     e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
                     e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex.ToString() + ")");
                     ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex.ToString() + ")");
                }
           }
       }
  }

  protected void grdReceivedNote_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  {
      grdReceivedNote.CurrentPageIndex = e.NewPageIndex;
      BindGridMaster();
  }
  protected void grdReceivedNoteDetails_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  {
      grdReceivedNoteDetails.CurrentPageIndex = e.NewPageIndex;
      BindGridMaster();
  }
  protected void grdReceivedNote_ItemCommand(object source, DataGridCommandEventArgs e)
  {
      string strCA = e.CommandArgument.ToString();

      switch (e.CommandName)
      {
          case "Edit":
             Insert = false;
             Id = strCA;
             ViewCustomers();
             ViewRevType();
             //ViewRevNote();
             //ViewItems();
             List<Data.ReceivedNote> listE = ReceivedNoteService.ReceivedNote_GetById(Id);
             txtRevNote_No.Text = listE[0].RevNote_No;
             txtRevDate.Text = listE[0].RevDate;
             txtNotes.Text = listE[0].Notes;
             drlCustIdAdd.SelectedValue = listE[0].CustID;
             drlRevTypeIdAdd.SelectedValue = listE[0].RevTypeID;
             pnViewMaster.Visible = false;
             pnUpdateMaster.Visible = true;
             break;

          case "Delete":
             ReceivedNoteService.ReceivedNote_Delete(strCA);
             BindGridMaster();
             break;
      }
  }
  protected void grdReceivedNoteDetails_ItemCommand(object source, DataGridCommandEventArgs e)
  {
      string strCA = e.CommandArgument.ToString();
      switch (e.CommandName)
      {
           case "Edit":
              Insert = false;
              Id = strCA;
              //ViewCustomers();
              //ViewRevType();
              ViewRevNote();
              ViewItems();
              List<Data.RevNoteDetails> listE = RevNoteDetailsService.RevNoteDetails_GetById(Id);

              txtQuantity.Text = listE[0].Quantity;
              drlRevNoteIdAdd.SelectedValue = listE[0].RevNoteID;
              drlItemIdAdd.SelectedValue = listE[0].ItemID;
              pnlViewDetails.Visible = false;
              pnlUpdateDetails.Visible = true;
          break;

          case "Delete":
              RevNoteDetailsService.RevNoteDetails_Delete(strCA);
              BindGridDetails();
          break;
     }
 }

0 个答案:

没有答案