To Get The Records In The RadGrid

7 posts, 0 answers
  1. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 15 Oct 2009 Link to this post

    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

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Oct 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 15 Oct 2009 Link to this post

    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
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Oct 2009 Link to this post

    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.
  6. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 16 Oct 2009 Link to this post

    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
  7. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 19 Oct 2009 Link to this post

    I just check the SQL return code from Oracle for a constraint violation and inform the user the record already exists.

    mark
  8. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 30 Oct 2009 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017