У меня есть 5 текстовых полей и два выпадающих списка.Я введу данные в текстовые поля и после нажатия кнопки «Добавить» все данные будут объединены в DataTable в VS2017.Я могу видеть данные из Datatable, но не могу увидеть данные на странице aspx.Как связать данные из DataTable с Grid Control, чтобы пользователь мог видеть данные.
Ниже приведен код со страницы 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;
Ниже приведен заголовок, который я включил:
<script type="text/javascript" src="../../javascript/Store/GrnEntry.js" language="javascript"></script>
<script type="text/javascript" src="../../javascript/Common/CommonScript.js" language="javascript"></script>
Ниже приведен файл JS:
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;
}
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>
Может ли кто-нибудь посоветовать по этому вопросу, пожалуйста?Как привязать данные из DataTable к Grid Control.