1
如何通過WCF在gridview中填充,創建,插入和刪除?通過WCF在Gridview上執行CRUD
我有問題,它無法找到fieldname
,但我可以獲取數據。
在我的服務代碼:
[DataContract]
public class Pers_Horraire
{
[DataMember]
string _ClientId;
public string ClientId
{
get { return _ClientId; }
set { _ClientId = value; }
}
[DataMember]
string _Horraire;
public string Horraire
{
get { return _Horraire; }
set { _Horraire = value; }
}
}
[OperationContract]
public IList<Pers_Horraire> Get_Horraire(string CodeCL)
{
try
{
using (var connectionWrapper = new Connexion())
{
var connectedConnection = connectionWrapper.GetConnected();
//string sql_SelectAll = Outils.LoadFileToString(HttpContext.Current.Server.MapPath("~/SQL/Ordre_Selt.sql"));
string sql_SelectAll = "SELECT CLIENT_ID,HORRAIRE FROM LS_CLIENTHORRAIRE WHERE CLIENT_ID = @CLIENT_ID";
SqlCommand comm_SelectAll = new SqlCommand(sql_SelectAll, connectionWrapper.conn);
comm_SelectAll.Parameters.AddWithValue("@CLIENT_ID", CodeCL);
SqlDataReader readerOne = comm_SelectAll.ExecuteReader();
List<Pers_Horraire> oListOrdr = new List<Pers_Horraire>();
Pers_Horraire obj_Horr = new Pers_Horraire();
while (readerOne.Read())
{
obj_Horr.ClientId = readerOne["CLIENT_ID"].ToString();
obj_Horr.Horraire = readerOne["HORRAIRE"].ToString();
oListOrdr.Add(obj_Horr);
}
readerOne.Close();
readerOne.Dispose();
return oListOrdr;
}
}
catch (Exception excThrown)
{
throw new Exception(excThrown.Message);
}
}
,我和電網消耗:
<dx:ASPxGridView ID="ASPxGridView_Horraire" runat="server"
KeyFieldName="CLIENT_ID;HORRAIRE"
OnRowInserting="Insrting_Horr_Obj"
OnRowUpdating="Updting_Horr_Obj"
OnRowDeleting="Delt_Horr_Obj" >
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0"
ButtonType="Image">
<DeleteButton Visible="True"
Image-Url="../images/Icon/delete-icon.png">
<Image Url="../images/Icon/delete-icon.png"></Image>
</DeleteButton>
<EditButton Visible="True"
Image-Url="../images/Icon/page-edit-icon.png" >
<Image Url="../images/Icon/page-edit-icon.png"></Image>
</EditButton>
<NewButton Visible="True"
Image-Url="../images/Icon/Plus-icon.png">
<Image Url="../images/Icon/Plus-icon.png"></Image>
</NewButton>
<CancelButton Image-Url="../images/Icon/Banned-icon.png">
<Image Url="../images/Icon/Banned-icon.png"></Image>
</CancelButton>
<UpdateButton Image-Url="../images/Icon/Good-or-Tick-icon.png">
<Image Url="../images/Icon/Good-or-Tick-icon.png"></Image>
</UpdateButton>
<ClearFilterButton Visible="True"
Image-Url="../images/Icon/System-Recyclebin-Empty-icon.png"
Image-ToolTip="Effacer Filtre" >
<Image ToolTip="Effacer
Filtre" Url="../images/Icon/System-Recyclebin-Empty-icon.png"> </Image>
</ClearFilterButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="HORRAIRE"
VisibleIndex="1"
Caption="Horraire" Width="10px">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
後面的代碼:
public void GetDataHorr()
{
try
{
Service1Client client = new Service1Client();
ASPxGridView_Horraire.DataSource = client.Get_Horraire(Id);
ASPxGridView_Horraire.DataBind();
//just to show i get the data from WCF
foreach (var oItem in client.Get_Horraire(Id))
{
ASPxLabel_err.Text += oItem + "_______";
}
}
catch (Exception excThrown)
{
ASPxLabel_err.Text = excThrown.Message + "-->" + excThrown.InnerException;
}
}
的問題無法找到FieldName="HORRAIRE"
所以如果我讓FieldName=""
它顯示我空列。
感謝您的回答。我根據您的建議修改了我的代碼,但不幸的是它仍然無法工作 – user609511