Hi, I am implemented a simple Grid that call Data from WCF, that was a normal JSON data.
I can show that data to grid every function on grid seem working well add, edit, delete, excepted the Export function
could you help me please..~~
##here is my screen##
<ej:grid runat="server" id="usersGrid" allowfiltering="true" allowpaging="true" allowresizing="true"
allowsorting="true" font-names="Phetsarath OT" isresponsive="true" allowsearching="true"
enableresponsiverow="true" onserveraddrow="usersGrid_ServerAddRow" onservereditrow="usersGrid_ServerEditRow"
onserverdeleterow="usersGrid_ServerDeleteRow" onserverexcelexporting="usersGrid_ServerExcelExporting">
<FilterSettings FilterType="Excel" />
<EditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true" ShowDeleteConfirmDialog="true" EditMode="Dialog"></EditSettings>
<ToolbarSettings ShowToolbar="true" ToolbarItems="add,edit,delete,update,cancel,search,excelExport,printGrid"></ToolbarSettings>
<Columns>
<ej:Column Field="id" HeaderText="ລດ" IsPrimaryKey="true" IsIdentity="true" AllowEditing="true" />
<ej:Column Field="username" HeaderText="ຊື່ຜູ້ໃຊ້" EditType="StringEdit" AllowEditing="true">
<ValidationRule>
<ej:KeyValue Key="required" Value="true" />
</ValidationRule>
</ej:Column>
<ej:Column Field="passwd" HeaderText="ລະຫັດຜ່ານ" EditType="StringEdit" AllowEditing="true">
<ValidationRule>
<ej:KeyValue Key="required" Value="true" />
</ValidationRule>
</ej:Column>
<ej:Column Field="rules" HeaderText="ສິດທິ (rw:ຜູ້ບໍລິຫານ, r:ຜູ້ໃຊ້)" EditType="DropdownEdit" AllowEditing="true">
<ValidationRule>
<ej:KeyValue Key="required" Value="true" />
</ValidationRule>
</ej:Column>
</Columns>
</ej:grid>
##and here is my code behide##
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
usersGrid.DataSource = GetgridData();
usersGrid.DataBind();
}
}
public List<GetUsers> GetgridData()
{
List<@GetUsers> gridData = new List<@GetUsers>();
wcf.parti.Service1 _parti = new wcf.parti.Service1();
partiDB.RootObject rootObject = new partiDB.RootObject();
string json_str = _parti.GetUsers("");
if (json_str == "e0")//code error
{
MessageBox.Show(this.Page, "en:code error.\\nlo: ລະບົບຂັດຂ້ອງຕິດຕໍ່ຜູ້ເບີ່ງແຍ່ງດ່ວນ.");
}
else if (json_str == "e1")//no data found
{
MessageBox.Show(this.Page, "en:no data found.\\nlo: ບໍ່ມີຂໍ້ມູນທີ່ຈະສະແດງ.");
}
else if (json_str == "e2")//can't connect databbase
{
MessageBox.Show(this.Page, "en:can't connect to database.\\nlo:ບໍ່ສາມາດເຊື່ອມຕໍ່ຖານຂໍ້ມູນໄດ້.");
}
else
{
rootObject = JsonConvert.DeserializeObject<partiDB.RootObject>(json_str);
foreach (var vl in rootObject.GetUsers)
{
gridData.Add(new GetUsers(vl.id, vl.username, enCoding.GetDecryptData(vl.passwd), vl.rules));
}
}
return gridData;
}
public class @GetUsers
{
public int id;
public string username;
public string passwd;
public string rules;
public GetUsers(int _id, string _username, string _passwd, string _rules)
{
this.id = _id;
this.username = _username;
this.passwd = _passwd;
this.rules = _rules;
}
}
protected void usersGrid_ServerExcelExporting(object sender, GridEventArgs e)
{
try
{
ExcelExport exp = new ExcelExport();
GridExcelExport excelExport = new GridExcelExport();
excelExport.FileName = "Export.xlsx";
excelExport.IsTemplateColumnIncluded = true;
excelExport.IsHideColumnIncude = true;
excelExport.Excelversion = ExcelVersion.Excel2010;
excelExport.Theme = "flat-lime";
exp.Export(usersGrid.Model, (IEnumerable)usersGrid.DataSource, excelExport); << ERROR on this row
}
catch (Exception ex)
{
MessageBox.Show(this.Page, "en:internal error.\\n(" + ex.Message + ")");
}
}
ERROR MESSAGE
| Name | Value | Type |
▶ | $exception | {"Object reference not set to an instance of an object."} | System.NullReferenceException
|