1
這是我的源代碼GridView控件,它必須是一個IListSource,IEnumerable的,或者的IDataSource
<asp:GridView ID="gveducationInfo" CssClass="footable" runat="server" AutoGenerateColumns="false" Style="max-width: 600px" ShowHeaderWhenEmpty="true" DataKeyNames="Education_ID" OnRowCommand="gveducationInfo_RowCommand">
<Columns>
<asp:BoundField DataField="Education_ID" HeaderText="" ItemStyle-CssClass="hiddenColumn" HeaderStyle-CssClass="hiddenColumn" />
<asp:BoundField DataField="Degree_Type" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Year_Of_Passing" HeaderText="Year Of Passing" />
<asp:BoundField DataField="Institute_Name" HeaderText="Institute Name" />
<asp:BoundField DataField="State_ID" HeaderText="State" />
<asp:BoundField DataField="City_ID" HeaderText="City" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<%--<asp:BoundField DataField="Notes" HeaderText="Notes" />--%>
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/edit16.png" CommandName="EditRow" ItemStyle-CssClass="align-center" />
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/delete16.png" CommandName="DeleteRow" ItemStyle-CssClass="align-center" />
</Columns>
</asp:GridView>
這是我的C#編碼
protected void butSave_ServerClick(object sender, EventArgs e)
{
Business.ATS.ATS ats = new Business.ATS.ATS();
Data.Education_Info education_Info = new Data.Education_Info();
var state = ats.GetStates();
var city = ats.GetCities();
education_Info = ats.GetEducationInfo(Applicant_ID).SingleOrDefault();
education_Info = new Data.Education_Info();
education_Info.Education_ID = 0;
education_Info.Applicant_ID = Applicant_ID;
education_Info.Name = txtdegreename.Value;
education_Info.Year_Of_Passing = txtyearofpassing.Value;
education_Info.Institute_Name = txtnameofinstitution.Value;
education_Info.City_ID = Convert.ToInt32(ddlcity.SelectedValue);
education_Info.State_ID = Convert.ToInt32(ddlstate.SelectedValue);
education_Info.Degree_Type = Convert.ToInt32(ddldegreetype.SelectedValue);
ats.SaveEducationalInfo(education_Info);
gveducationInfo.DataSource = ats.GetEduInfo().Last();
gveducationInfo.DataBind();
}
這是我的實體framwork DB代碼
public IList<Education_Info> GetEduInfo()
{
using (Data.ATSEntities dc = new Data.ATSEntities())
{
var lsteducationinfo = dc.Education_Info.ToList();
return lsteducationinfo;
}
}
當我填寫網頁中的細節,然後單擊保存頁面我需要獲取用戶在gridview中輸入的最後一條記錄,請輸入錯誤代碼
數據源是無效類型。它必須是IListSource, IEnumerable或IDataSource。
有人知道如何騎它嗎?
我刪除了最後(),但我在網頁電網得到了全表,但我只需要最後一個記錄該用戶已進入。那可能嗎?? @Shaun Luttin –
@KarthikeyanMuthukumaran是的。這是可能的。查看修改。 –
非常感謝你@Shaun Luttin –