Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据未显示在网格控件Asp.net C#中,但显示在DataTable中_C#_Asp.net_Grid_Controls - Fatal编程技术网

数据未显示在网格控件Asp.net C#中,但显示在DataTable中

数据未显示在网格控件Asp.net C#中,但显示在DataTable中,c#,asp.net,grid,controls,C#,Asp.net,Grid,Controls,我有5个文本框和两个下拉列表。我将在文本框中输入数据,单击“添加”按钮后,所有数据在VS2017的数据表中显示。我可以看到Datatable中的数据,但无法看到aspx页面中的数据。 如何将数据表中的数据绑定到网格控件,以便用户可以看到数据 以下是CS页面的代码: Griddt.Columns.Add("SrlNo", typeof(string)); Griddt.Columns.Add("GrnNo", typeof(string));

我有5个文本框和两个下拉列表。我将在文本框中输入数据,单击“添加”按钮后,所有数据在VS2017的数据表中显示。我可以看到Datatable中的数据,但无法看到aspx页面中的数据。 如何将数据表中的数据绑定到网格控件,以便用户可以看到数据

以下是CS页面的代码:

            Griddt.Columns.Add("SrlNo", typeof(string));
            Griddt.Columns.Add("GrnNo", typeof(string));
            Griddt.Columns.Add("GrnDate", typeof(string));
            Griddt.Columns.Add("ItemName", typeof(string));
            Griddt.Columns.Add("ItemCode", typeof(string));
            Griddt.Columns.Add("ChallanQty", typeof(string));
            Griddt.Columns.Add("StoreQty", typeof(string));
            Griddt.Columns.Add("ContainerType", typeof(string));
            Griddt.Columns.Add("ActuallQty", typeof(string));
            Griddt.Columns.Add("PcsQty", typeof(string));
            Griddt.Columns.Add("PONo", typeof(string));

            DataRow drGriddtRow = Griddt.NewRow();

            Newdt.Columns.Add("SrlNo", typeof(string));
            Newdt.Columns.Add("GrnNo", typeof(string));
            Newdt.Columns.Add("GrnDate", typeof(string));
            Newdt.Columns.Add("ItemName", typeof(string));
            Newdt.Columns.Add("ItemCode", typeof(string));
            Newdt.Columns.Add("ChallanQty", typeof(string));
            Newdt.Columns.Add("StoreQty", typeof(string));
            Newdt.Columns.Add("ContainerTypeCode", typeof(string));
            Newdt.Columns.Add("ContainerTypeDescription", typeof(string));

            Newdt.Columns.Add("ActuallQty", typeof(string));
            Newdt.Columns.Add("PcsQty", typeof(string));
            Newdt.Columns.Add("PONo", typeof(string));


            DataRow drNewdtRow = Newdt.NewRow();


            if (Session["DtAll"] != null)
            {
                DtAll = (DataTable)(Session["DtAll"]);
                for (int i = 0; i < DtAll.Rows.Count; i++)
                {
                    if (DtAll.Rows[i]["ItemCode"].ToString().ToLower() == ddlItemName.SelectedValue.ToString().ToLower())
                    {
                        MsgBox("Duplicated Item!!");
                        return;
                    }
                }

            }


            drNewdtRow["SrlNo"] = "1";

            drNewdtRow["GrnNo"] = txtGrnNo.Text;
            drNewdtRow["GrnDate"] = txtGrnDate.Text;
            drNewdtRow["ItemName"] = ddlItemName.SelectedItem.Text;
            drNewdtRow["ItemCode"] = ddlItemName.SelectedValue.ToString();
            drNewdtRow["ChallanQty"] = Convert.ToDecimal(txtChallanQty.Text);
            if (txtStoreQty.Text == "")
            {
                drNewdtRow["StoreQty"] = "0";
            }
            else
            {
                drNewdtRow["StoreQty"] = Convert.ToDecimal(txtStoreQty.Text);
            }

            drNewdtRow["ContainerTypeCode"] = ddlContainerType.SelectedValue.ToString().Trim();
            drNewdtRow["ContainerTypeDescription"] = ddlContainerType.SelectedItem.Text.Trim();
            drNewdtRow["ActuallQty"] = Convert.ToDecimal(txtActuallQty.Text);
            drNewdtRow["PcsQty"] = "0";

            //if (ddlItemName.SelectedValue.Substring(4, 1) == "F")
            //    drNewdtRow["PONo"] = "-";
            //else
            //    drNewdtRow["PONo"] = ddlPONo.SelectedItem.Text.Trim();

            if (ddlPurchaseType.SelectedItem.Text == "Credit Purchase")
            {
                if (ddlItemName.SelectedValue.Substring(4, 1) == "F")
                    drNewdtRow["PONo"] = "-";
                else
                    drNewdtRow["PONo"] = ddlPONo.SelectedItem.Text.Trim();
            }
            else
            {
                drNewdtRow["PONo"] = "-";
            }


            //if (ddlItemName.SelectedValue.ToString().Substring(4, 1) == "P")
            //{
            //    drNewdtRow["PcsQty"] = txtPcs.Text;
            //}
            //else
            //{
            //    drNewdtRow["PcsQty"] = "0";
            //}

            Newdt.Rows.Add(drNewdtRow);

            Griddt = Newdt.Copy();
            if (Session["DtAll"] != null)
            {
                DtAll = (DataTable)(Session["DtAll"]);
            }
            DtAll.Merge(Griddt, true);
            DtAll.AcceptChanges();
            GrdGRn.DataSource = DtAll;
            Session["DtAll"] = DtAll;                        
            GrdGRn.DataBind();
            GrdGRn.Visible = true;
HTML代码:

<asp:GridView ID="GrdGRn" runat="server" Height="61px" Width="650px" ForeColor="Black" BackColor="LightGoldenrodYellow" CellPadding="2" BorderWidth="1px" BorderColor="Tan" GridLines="None" AutoGenerateColumns="False" PageSize="5" OnRowDataBound="GrdGRn_RowDataBound" OnRowCommand="GrdGRn_RowCommand"  OnRowDeleting="GrdGRn_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="SrlNo" Visible="False">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("SrlNo") %>' ID="LblSrlNo"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ItemCode" HeaderText="ItemCode"></asp:BoundField>
<asp:TemplateField HeaderText="Item Name"><EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblItemName" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label></ItemTemplate></asp:TemplateField>
<asp:BoundField DataField="ChallanQty" HeaderText="ChallanQty"></asp:BoundField>
<asp:BoundField DataField="StoreQty" HeaderText="StoreQty"></asp:BoundField>
<asp:TemplateField HeaderText="ContainerTypeCode" Visible="False">
<ItemTemplate><asp:Label ID="lblContainerTypeCode" runat="server" Text='<%# Bind("ContainerTypeCode") %>'></asp:Label></ItemTemplate>
</asp:TemplateField><asp:BoundField DataField="ContainerTypeDescription" HeaderText="ContainerTypeDescription"></asp:BoundField>
<asp:BoundField DataField="ActuallQty" HeaderText="ActuallQty"></asp:BoundField>
<asp:BoundField DataField="PcsQty" HeaderText="PcsQty"></asp:BoundField>
<asp:BoundField DataField="PONo" HeaderText="PONo"></asp:BoundField>
<asp:TemplateField HeaderText="Delete"><ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:LinkButton ID="lnkB" runat="server" CommandArgument='<%#Eval("ItemName")%>'
 CommandName="Delete" Text="Delete">
</asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Tan"></FooterStyle><PagerStyle HorizontalAlign="Center" BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue">
</PagerStyle>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"></SelectedRowStyle>
<HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
<AlternatingRowStyle BackColor="PaleGoldenrod"></AlternatingRowStyle>
</asp:GridView>


有人能给我一些建议吗?如何将数据表中的数据绑定到网格控件。

问题可能出在aspx页面上。你能把网格定义放在asp中吗?我已经把网格定义上传到了aspmmm中。奇怪。在数据源的DtAll不工作之前,可能尝试获取dgv visible=true。。。网格上没有显示任何数据。。。
function fnCheckValidation()
{
    var Item= document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_ddlItem");
    var ItemName=document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txtItemName");
    var ChallanQty=document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txtChallanQty");
    var ActuallQty =document.getElementById("ctl00_ContentPlaceHolder1_TabContainer1_TabPanel1_txtActuallQty");
    var TotChalan=document.getElementById("ctl00_ContentPlaceHolder1_txtTotChallanQty");
    var TotRecvd= document.getElementById("ctl00_ContentPlaceHolder1_txtTotRecvdQty");

if(Item.value=="")
    { 
        alert("Please Select Item!");
        Item.focus();
        return false; 

    }

    if(ChallanQty.value=="")
    {
        alert("Please Enter Challan Qty!");
        return false; 
    }

    if(ActuallQty.value=="")
    {
        alert("Please Enter Actuall Qty!");
        return false; 
    }

    TotChalan.readOnly= true;
    TotRecvd.readOnly= true;


    return true;

}



function fnClearAll()
{
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtBranchCode").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_TxtBranchName").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_ddlState").value="--Select State--";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_ddlCity").value="--Select City--";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtFloor").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtRoomNumber").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtPinCode").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtEmailId").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtFax").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtPostOffice").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtPoliceStation").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtMetro").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_txtRemarks").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_Branch1_ddlDivision").value = "--Select Division--";

}

function setMouseClick()
{
    //
    var argv = setMouseClick.arguments;
    var argc = argv.length;

    var Subledger= document.getElementById("ctl00_ContentPlaceHolder1_txtDescription");
    var Subledgeraccount=document.getElementById("ctl00_ContentPlaceHolder1_ddlAccounts");




    SubMajorHeadNo.value=argv[0];
    SubMajorHeadname.value=argv[1];
    ddlsub.value=argv[2]
    SubMajorHeadNo.readOnly=true;
    return true;
}
<asp:GridView ID="GrdGRn" runat="server" Height="61px" Width="650px" ForeColor="Black" BackColor="LightGoldenrodYellow" CellPadding="2" BorderWidth="1px" BorderColor="Tan" GridLines="None" AutoGenerateColumns="False" PageSize="5" OnRowDataBound="GrdGRn_RowDataBound" OnRowCommand="GrdGRn_RowCommand"  OnRowDeleting="GrdGRn_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="SrlNo" Visible="False">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("SrlNo") %>' ID="LblSrlNo"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ItemCode" HeaderText="ItemCode"></asp:BoundField>
<asp:TemplateField HeaderText="Item Name"><EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblItemName" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label></ItemTemplate></asp:TemplateField>
<asp:BoundField DataField="ChallanQty" HeaderText="ChallanQty"></asp:BoundField>
<asp:BoundField DataField="StoreQty" HeaderText="StoreQty"></asp:BoundField>
<asp:TemplateField HeaderText="ContainerTypeCode" Visible="False">
<ItemTemplate><asp:Label ID="lblContainerTypeCode" runat="server" Text='<%# Bind("ContainerTypeCode") %>'></asp:Label></ItemTemplate>
</asp:TemplateField><asp:BoundField DataField="ContainerTypeDescription" HeaderText="ContainerTypeDescription"></asp:BoundField>
<asp:BoundField DataField="ActuallQty" HeaderText="ActuallQty"></asp:BoundField>
<asp:BoundField DataField="PcsQty" HeaderText="PcsQty"></asp:BoundField>
<asp:BoundField DataField="PONo" HeaderText="PONo"></asp:BoundField>
<asp:TemplateField HeaderText="Delete"><ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:LinkButton ID="lnkB" runat="server" CommandArgument='<%#Eval("ItemName")%>'
 CommandName="Delete" Text="Delete">
</asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Tan"></FooterStyle><PagerStyle HorizontalAlign="Center" BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue">
</PagerStyle>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"></SelectedRowStyle>
<HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
<AlternatingRowStyle BackColor="PaleGoldenrod"></AlternatingRowStyle>
</asp:GridView>