Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
Table doesn't have primary key on checkbox check
posted

Hi I am using infragistics webdatagrid v15.2. I am editing a column and the data is updating on ExitedEditMode. But when I edit the column and check the checkbox to load the grid on checkchanged I am getiing table doesn't have primary key error.But there is primary key set for the table.Below is the code .How to fix this? Please guide me with the steps.

public partial class ExceptionReportA23 : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
currentPage = "ExceptionReportA23";

if (currentMI.modelInstanceID == Guid.Empty)
{
Response.Redirect("Default.aspx");
return;
}

loadExceptionsGrid();


}

private void loadExceptionsGrid()
{
ExceptionService svc = new ExceptionService();
DataSet reportData = new DataSet();

try
{
reportData = svc.getAccountEdits(currentMI.modelInstanceID);
foreach (DataRow dr in reportData.Tables[0].Rows)
{

// ,[ST_CHECK_REQUIRED]
//,[ST_CHECK_15]
//,[ST_CHECK_LOB]
//,[ST_CHECK_ST]
double year1;
double year1change;

bool year1result = double.TryParse(dr["YEAR1"].ToString(), out year1);
bool year1changeresult = double.TryParse(dr["YEAR1CHANGE"].ToString(), out year1change);

//year1change = year1change / 100; //percent
bool ST_CHECK_REQUIRED;
bool.TryParse(dr["ST_CHECK_REQUIRED"].ToString(), out ST_CHECK_REQUIRED);
bool ST_CHECK_15;
bool.TryParse(dr["ST_CHECK_15"].ToString(), out ST_CHECK_15);
bool ST_CHECK_LOB;
bool.TryParse(dr["ST_CHECK_LOB"].ToString(), out ST_CHECK_LOB);
bool ST_CHECK_ST;
bool.TryParse(dr["ST_CHECK_ST"].ToString(), out ST_CHECK_ST);

Guid ST_ID = new Guid(dr["ST_ID"].ToString());
Guid LB_ID = new Guid();
if (dr["LB_ID"].ToString() != "")
{
LB_ID = new Guid(dr["LB_ID"].ToString());
}

if (ST_CHECK_REQUIRED == true && (year1result == false || year1 == 0))
{
dr["EXCEPTION"] = "1";
}
if (ST_CHECK_15 == true && year1changeresult == true && (year1change >= .15 || year1change <= -.15))
{
dr["EXCEPTION"] += " 2";
}
if (ST_CHECK_LOB == true && LB_ID != Guid.Empty && year1result != false && year1 != 0 && svc.getA23LBCheck(currentMI.modelInstanceID, ST_ID, LB_ID) != 1)
{
dr["EXCEPTION"] += " 3";
}
if (ST_CHECK_ST == true && LB_ID != Guid.Empty && (year1result == false || year1 == 0) && svc.getA23LBCheck(currentMI.modelInstanceID, ST_ID, LB_ID) == 1)
{
dr["EXCEPTION"] += " 4";
}

if (dr["EXCEPTION"].ToString() == "" && chkShowAll.Checked == false)
{
dr.Delete();
}
}
WebDataGrid1.DataSource = reportData;
WebDataGrid1.DataBind();
WebDataGrid1.Columns[5].Header.Text = currentMI.modelInstanceYear.ToString();
WebDataGrid1.Columns[6].Header.Text = (currentMI.modelInstanceYear - 1).ToString();
}
catch (Exception exp)
{
logutils.createExceptionLogEntry(exp, loggedInUserID);
//msgs.Add(CONST_ERR_MSG_GENERIC);
//if (modelType == null)
// msgs.Add("Most likely this occurred because an active client related identifier was not passed.");
}

}
protected void btnExportToExcel_Click(object sender, EventArgs e)
{

Infragistics.Documents.Excel.Workbook workbook = new Infragistics.Documents.Excel.Workbook();
workbook.Worksheets.Add(currentMI.modelInstanceID.ToString().Substring(0, 31).Replace("-", ""));
WebExcelExporter1.Export(workbook.Worksheets[0], 1, 0, WebDataGrid1);
}

protected void chkShowAll_CheckedChanged(object sender, EventArgs e)
{
loadExceptionsGrid();
}

}

Javascript function to update 


function WebDataGrid1_ExitedEditmode(sender, eventArgs) {
//var cell = igtbl_getCellById(cellId);
//var row = cell.getRow();
// need to implement for notes
var grid = $find("<%=WebDataGrid1.ClientID%>");
var gridBehaviors = grid.get_behaviors();
var notes = eventArgs.getCell().get_row().get_cellByColumnKey("EX_NOTE").get_value();
abmAPI.insertExceptionA23Notes(eventArgs.getCell().get_row().get_cellByColumnKey("ST_ID").get_value(), eventArgs.getCell().get_row().get_cellByColumnKey("LB_ID").get_value(),
notes!=null?notes:" ", insertExceptionA23NotesHandler);
}

  • 25665
    Offline posted

    Hello Prabhakar,

    Thank you for contacting Infragistics!

    The code you provide does not contain any code setting the primary key. You appear to being using a DataSet. Since you are assigning to the WebDataGrid which handles flat data I recommend you use a DataTable. In addition you will want to set the primary key, something like the following:

    dtData.PrimaryKey = new DataColumn[] { dtData.Columns["EmployeeID"] };

    You will also want to make sure to set the DataKeyFields of the WebDataGrid to a column with unique values most likely your PrimaryKey field.