Wednesday, May 23, 2012

Find Label Control from Item Temple of RadGrid

Problem:

I am using GridTemplateColumn in RadGrid and I want find the label control which is in grid's ItemTemplate to update record.

I am using this code in grid's updatecommand,

VB CODE:
Dim Label1 As Label = CType(e.Item.FindControl("Label1"), Label)

but control is not found thus there is (nothing) in Label1.

Solution:

Try this,

VB CODE:
Dim Label1 As Label = DirectCast(CType(e.Item, GridEditFormItem).OwnerTableView.Items(e.Item.ItemIndex).FindControl("Label1"), Label)

Sunday, April 22, 2012

Code Snippets


Introduction:

Snippet is a programming term for a small region of re-usable source code, machine code or text. Code Snippets provide a way for you to insert ready-made snippets of code into your projects.

Advantages:

  • Write once use anywhere: Reduce the repeatable writing of code effort.
  • Define/Maintain a Coding Standard to be used for any Project/Organization.
  • Easy to use as well as create and also easily maintainable.
  • Share with other developers.
  • Increase productivity by making coding faster.

Creating a Snippet File:

To create a snippet file, you must create an XML file, and then write the XML code that makes up your code snippet.
Following are the steps to create a snippet file:

Step1



Step 2



Step 3



Step 4



Step 5



Step 6


Manage Code Snippets:

The Code Snippets Manager allows you to set the directories and individual snippets that you want available to insert into your code.

To access the Code Snippets Manager :

      On the Tools menu, click Code Snippets Manager.

To add a directory to the Code Snippet Manager :

In the Language: drop-down list, select the language that you want to add a directory to.
Click Add. This opens the Code Snippets Directory window.
Select the directory that you want to add to the Code Snippets Manager and click ‘OK’. The directory will now be used to search for available code snippets.

Monday, January 23, 2012

Update In LINQ not Working

Problem: I am working on a console application and I have a table in my .DBML File as FirstTable
I am using following code written below to update a field "Father Name" but it is still not updating it in Relational Database MS SQL.

VB Code:
Imports System.Data
Imports System.Collections.Generic
Module Module2
    Dim DB As New NorthWinddatacontext()

    Sub main()

        Dim UpdateName = (From p In DB.FirstTables Where p.Name = "Yousuf"
                       Select p).Single

        UpdateName.FatherName = "Hashmi1"
        DB.SubmitChanges()
    End Sub

My code is not working

Solution: You have not set any Primary Key on Your Table  in your Relational Database.Make a Primary Key and try the same code again by Droping the table again on Your DBML.

Friday, January 20, 2012

is neither a DataColumn nor a DataRelation for table DefaultView

Problem: I get this error when I try to filter any column in my RadGrid.I am using template columns.

"is neither a DataColumn nor a DataRelation for table DefaultView"

Here is my code of a Column
<telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="PO #" Visible="true">
 <ItemTemplate>
<asp:Label ID="lblPONumber" Text='<%# Eval("_PONumber") %>' runat="server">
</asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</telerik:GridTemplateColumn>


Solution: You have to check that DataField property is present or not.

Here is corrected Code
<telerik:GridTemplateColumn DataField="_PONumber" HeaderStyle-HorizontalAlign="Center" HeaderText="PO #" Visible="true">
 <ItemTemplate>
<asp:Label ID="lblPONumber" Text='<%# Eval("_PONumber") %>' runat="server">
</asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</telerik:GridTemplateColumn>

Wednesday, January 18, 2012

First Column of RadGrid to stay visible

Problem: I have many columns in my RadGrid ,I want first column to stay visible while scrolling.Only first column should appear all the time.
Solution: This can be done using FrozenColumnsCount in ClientSettings tag.

Example:
<telerik:RadGrid ID="radGridServices" runat="server">
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="Services_ID_PK" ClientDataKeyNames="Services_ID_PK">
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" FrozenColumnsCount="1" SaveScrollPosition="true" UseStaticHeaders="true" />
        <ClientEvents />
    </ClientSettings>
</telerik:RadGrid>