我目前正在处理.net项目,我需要做的是从Web Service获取数据并将其显示在网格中。由于某些原因,我不知道网格未显示数据。 这是我的aspx.cs文件
protected void radGridPensionList_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (IsPostBack)
{
ArrayList list = new ArrayList();
string ssn = txtSSN.Text.ToString();
getMypensionListWS pensionList = new getMypensionListWS();
myPensionerProfitList[] arrayOfPensionList = getPensionProfitList(ssn);
for (int i = 0; i < arrayOfPensionList.Length; i++)
{
myPensionerProfitList ARRAY = arrayOfPensionList[i];
DataTable dt = new DataTable(); //Get details
list.Add(arrayOfPensionList);
}
radGridPensionList.DataSource = list;
}
}
和带有网格代码的aspx文件
<telerik:RadGrid ID="radGridPensionList" runat="server" OnNeedDataSource="radGridPensionList_NeedDataSource"
AllowFilteringByColumn="True" CellSpacing="-1" GridLines="Both" AutoGenerateColumns="false" >
<clientsettings allowcolumnsreorder="True">
<Selecting AllowRowSelect="True" />
</clientsettings>
<%-AutoGenerateColumns =“ true”-%>
<Columns>
<%-- <telerik:GridBoundColumn DataField="CUSTOMER_NO" UniqueName="Customer_No" Display="true">
</telerik:GridBoundColumn>--%>
<telerik:GridBoundColumn DataField="PERSON_ID" HeaderText="PERSON_ID" UniqueName="PERSON_ID" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FIRST_NAME" HeaderText="FIRST_NAME" UniqueName="FIRST_NAME" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FATHER_NAME" HeaderText="FATHER_NAME" UniqueName="FATHER_NAME" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LAST_NAME" HeaderText="LAST_NAME" UniqueName="LAST_NAME" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BIRTH_DATE" HeaderText="BIRTH_DATE" UniqueName="BIRTH_DATE" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PFILE_CODE" HeaderText="PFILE_CODE" UniqueName="PFILE_CODE" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FILE_TYPE" HeaderText="FILE_TYPE" UniqueName="FILE_TYPE" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BIRTH_DAPFILE_DOCUMENT_IDTE" HeaderText="PFILE_DOCUMENT_ID" UniqueName="PFILE_DOCUMENT_ID" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PERIOD_ID" HeaderText="PERIOD_ID" UniqueName="PERIOD_ID" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PERIOD_NAME" HeaderText="PERIOD_NAME" UniqueName="PERIOD_NAME" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PO_CHECK" HeaderText="PO_CHECK" UniqueName="PO_CHECK" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AMOUNT" HeaderText="AMOUNT" UniqueName="AMOUNT" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PFILE_POP_ID" HeaderText="PFILE_POP_ID" UniqueName="PFILE_POP_ID" Display="true">
</telerik:GridBoundColumn>
</Columns>
<PagerStyle AlwaysVisible="true" />
</MasterTableView>
</telerik:RadGrid>
该代码未给出错误或异常。我可以看到网格将我的列表作为数据源,但是运行该应用程序时却什么也没有显示。 知道我在哪里做错了吗?任何建议表示赞赏。
答案 0 :(得分:1)
您的代码正在做一些奇怪的事情。
ArrayList
。由于您可以向其中添加任何对象,因此很难看到您正在添加像您一样的奇怪事物(请参见下文)。请改用List<T>
,以便您可以定义可以添加到列表中的内容。ARRAY
和dt
)。list
中。我怀疑您只想将项添加到数组中,而不是数组本身:更新了代码:
if (IsPostBack)
{
var list = new List<myPensionerProfitList>();
string ssn = txtSSN.Text.ToString();
getMypensionListWS pensionList = new getMypensionListWS();
myPensionerProfitList[] arrayOfPensionList = getPensionProfitList(ssn);
for (int i = 0; i < arrayOfPensionList.Length; i++)
{
myPensionerProfitList item = arrayOfPensionList[i];
list.Add(item);
}
radGridPensionList.DataSource = list;
}
应该工作。如果起作用,您可以通过在 array 上调用Linq ToList
方法来创建列表来简化它。或者,因为您可以将数组绑定到数据网格就很好了,所以根本不需要列表 :
if (IsPostBack)
{
string ssn = txtSSN.Text.ToString();
getMypensionListWS pensionList = new getMypensionListWS();
myPensionerProfitList[] arrayOfPensionList = getPensionProfitList(ssn);
radGridPensionList.DataSource = arrayOfPensionList;
}