This is a migrated thread and some comments may be shown as answers.

To Get The Records In The RadGrid

6 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 15 Oct 2009, 06:23 AM
Hi All

I have a grid wih some 25 records.

While inserting a new record need to check whether it constains duplication.

So I have taken the recods in the grid  and checked.

protected

void RadGridEmpType_InsertCommand(object source, GridCommandEventArgs e)

 

{

 

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

 

 

Hashtable newValues = new Hashtable();

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, insertedItem);

 

int value = 0;

 

 

RadTextBox txt = (RadTextBox)e.Item.FindControl("txtTypeShortDesc");

 

 

int Rowcount = RadGridEmpType.Items.Count;

 

 

for (int count = 0; Rowcount > count; count++)

 

{

 

Label lbl = (Label)RadGridEmpType.Items[count].FindControl("LblTypeShortDesc");

 

 

if (txt.Text.ToUpper() == lbl.Text.ToUpper())

 

{

value++;

}

}

 

if (value == 0)

 

{

dsiSmartEmpType.InsertParameters[0].DefaultValue = CompanyID.ToString();

dsiSmartEmpType.InsertParameters[1].DefaultValue = UserId;

}

 

else

 

{

 

Label lbl = (Label)e.Item.FindControl("Msg");

 

lbl.Text =

"Already Exists";

 

e.Canceled =

true;

 

}

}

It works.

But It just takes the record in the current page.

For example the grid contains 25 records. and the page size is given as 10.

While inserting it just checks the last five.

Is there any option to take all the 25 records in the grid.

Thank You.

-Anto

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 15 Oct 2009, 07:16 AM
Hello Anto,

I tried setting the AllowPaging property to false and then loop through the griditems for checking whether the values already exists or not. Give a try with this approach.

C#:
 
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    TextBox txt = (TextBox)e.Item.FindControl("txtTypeShortDesc"); 
    RadGrid1.AllowPaging = false
    RadGrid1.Rebind(); 
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
    { 
        if (txt.Text == item["LblTypeShortDesc"].Text.ToString()) 
        { 
            Response.Write("Already exists"); 
            e.Canceled = true
        }             
    } 
    RadGrid1.AllowPaging = true
    RadGrid1.Rebind(); 

-Shinu.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 15 Oct 2009, 01:41 PM
Hi Shinu,

I have replaced the existing set of code with the code you have sent.

If I try to insert a record.

An error appears.

Cannot find a cell bound to column name 'LblTypeShortDesc'

In my aspx page. I have used:

<

telerik:GridTemplateColumn UniqueName="TypeShortDesc" DataField="TypeShortDesc" ItemStyle-Width="15%"

 

 

HeaderText="Short Description">

 

 

<ItemTemplate>

 

 

<asp:Label ID="LblTypeShortDesc" Text='<%#Eval("TypeShortDesc")%>' runat="server"></asp:Label>

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<telerik:RadTextBox ID="txtTypeShortDesc" TextMode="SingleLine" MaxLength="5" Text='<%#Bind("TypeShortDesc")%>'

 

 

runat="server" ToolTip="Maximum Character Allowed is 5" ></telerik:RadTextBox><asp:Label ID = "Label1" runat = "server" ForeColor = "Red" Text="*" ></asp:Label>

 

 

<asp:RequiredFieldValidator ID="RequiredFieldValidatorTypeShortDesc" runat="server"

 

 

ErrorMessage="" ControlToValidate="txtTypeShortDesc"></asp:RequiredFieldValidator>

 

 

<asp:Label ID = "Msg" runat = "server" ForeColor = "Red"></asp:Label>

 

 

<asp:RegularExpressionValidator ID="RegularExpressionValidatorTypeShortDesc" runat="server"

 

 

ControlToValidate="txtTypeShortDesc" ValidationExpression="^[a-zA-Z0-9]+$" ErrorMessage="Special Characters not Allowed"></asp:RegularExpressionValidator>

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 



-Anto
0
Shinu
Top achievements
Rank 1
answered on 16 Oct 2009, 07:24 AM
Hi Anto,

You can replace this line of the code:
 if (txt.Text == item["LblTypeShortDesc"].Text.ToString())  // to replace  
        {  
            Response.Write("Already exists");  
            e.Canceled = true;  
        }             

 with the following code:
if (txt.Text == ((Label)item.FindControl("LblTypeShortDesc").Text).ToString()) //replaced 
        {  
            Response.Write("Already exists");  
            e.Canceled = true;  
        }              

-Shinu.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 16 Oct 2009, 11:46 AM
Hi Shinu,

I raplaced the line. Then I got the error.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'Already exists16964|'.

Then I replaced the Lines:

 

 

if (txt.Text == (((Label)item.FindControl("LblTypeShortDesc")).Text).ToString())  
{  
    Response.Write("Already exists");   
    e.Canceled = true;   
}  
 
 
 

To

 

 

if (txt.Text == (((Label)item.FindControl("LblTypeShortDesc")).Text).ToString())  
{  
     Label lbl = (Label)e.Item.FindControl("Msg");   
     lbl.Text = "Already Exists";   
     e.Canceled = true;   

Now No Error appears.

But Nothing happened when the insert button is clicked.

Record was not inserted, But the message didn't appear "Already Exists".

-Anto
0
Mark Galbreath
Top achievements
Rank 2
answered on 19 Oct 2009, 08:49 PM
I just check the SQL return code from Oracle for a constraint violation and inform the user the record already exists.

mark
0
Brett
Top achievements
Rank 2
answered on 31 Oct 2009, 12:52 AM
Hi Shinu,
 I am hoping you can help, I am trying to do somewhat the idea as stated above.
Please see my thread here: http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-check-if-grid-item-exists-in-second-grid.aspx

Basically I want two test if a value already exist in a second grid before my insert runs from a button click event.
Would appreciate any help you can provide.

Thanks
Brett
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Mark Galbreath
Top achievements
Rank 2
Brett
Top achievements
Rank 2
Share this question
or