ASP.NET Interview Questions and Answers (1544) - Page 59

How to get Selected Text values from Dropdown list control?

There is a Dropdown list SelectedValue property by which we can get Dropdown list selected item values.

For Example:-

int value = Convert.ToInt32(ddl_employee.SelectedValue);

How to Display the First and Last Names in a Single Column in Gridview?

We can write code inside ItemTemplate as

<asp:GridView ID="grid_employee_details" runat="server">

<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_employee_full_name" runat="server" Text='<%#eval("first_name") & " " & eval("last_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

What does BoundField mean in Gridview?

The BoundField,which displays the value of specified DataSource field as text.This is the type of column used by default when tying a GridView to a DataSource through the Smart Tag interface.

This is said to be a Read-only field.It has DataField property.We have provide DataField to a column_name.

Like below:

<asp:GridView ID="grid_employee_details" runat="server" AutoGenerateColumns="false">

<Columns>
<asp:BoundField HeaderText="Employee Name" DataField = "first_name" />
</Columns>
</asp:GridView>

What is the Difference between Templatefield and Boundfield in Gridview?

When we bind GridView with some columns like ID,Name,City etc.,these columns will display as BoundFields.
Bound means which Columns we bound to Gridview or any control.

Suppose,we want to make some changes in existing display i.e. instead of Label control if we want to display any data in TextBox or Button then we can use Templatefield.

In short,BoundField is only used for display record i.e. it's Read-only fields means we can only view data but can not Edit
whereas TemplateField is used for both viewing as well as editing records.With the help of ItemTemplate and EditItemTemplate we can view as well as edit data.
What is the use of DataFormatString in Gridview?

DataFormatString as name suggested,is used for formatting of data inside Gridview.We give DataFormatString in BoundField to format as we want like date in any format,currency and so on.

For Example:-
<asp:BoundField DataField="created_date" DataFormatString="{0:d}" HeaderText = "Created Date"/>


<asp:BoundField DataField="salary" HeaderText="Salary" DataFormatString="{0:C}" />

What do we mean by NullDisplayText Property in Gridview?

NullDisplayText as name implies,it display any text in the column,when that column has no record or null or empty records.If the record is Null or Empty,then in such case,we use NullDisplayText property to show user as any user defined text in columns.

We give this property in BoundField as shown below:-

<asp:BoundField HeaderText="LDAP" DataField = "ldap" NullDisplayText="Not Present" />


In above case if employee'LDAP is not found in DB or Null or Empty,then in that case it will show Not Present in Gridview.
What property do we require to add within the Gridview tags to bind columns manually?

We have to set AutoGenerateColumns Property to false on the Gridview to bind columns manually.In such case,we have to write code inside TemplateField or BoundField.

<asp:GridView ID="grid_employee_details" runat="server" AutoGenerateColumns="false">

<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_employee_full_name" runat="server" Text='<%#eval("first_name") & " " & eval("last_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField HeaderText="Employee Name" DataField = "middle_name" NullDisplayText="Not Found" />
</Columns>
</asp:GridView>

What is the life of a View-State items?

Items stored in a View State exist for the life of the current page.If we navigate to the other page,then ViewState information is lost.

That is the only reason,we can not access ViewState in different pages.Because it's designed to work in same page only.
Which property is used to bind Repeater Control?

DataSource property and DataBind() method is used to bind Repeater Control.As we know that Repeater Control also comes under DataBound control and DataSource property and DataBind() method is used for binding any object to databound controls.

For Example:-

rpt_project_details.DataSource = dt;

rpt_project_details.DataBind()


Here,dt is our DataTable object.
What is the best example of Fragment Caching?

User Control is the best example of Fragment Caching,because Fragment Caching only caches/stores the portion of page.and user control is used for lay-out purposes.
What is dynamic language runtime?

DLR is a runtime nviroment that allows us to inetgrate dynamic languages with common language runtime(CLR) by adding set of services, such as expression trees, call site caching, and dynamic object interoperability to the CLR.

The various advantages provided by DLR are:
1. Allows you to easily implement the dynamic languages to the .NET Framework.
2. Provides dynamic features to statically-typed languages. The statically-typed .NET Framework languages, such as C# and Visual Basic can create dynamic objects and use them together with statically-typed objects.
3. Implements sharing of libraries and objects, which means that the objects and libraries implemented in one language can be used by other languages using DLR. The DLR also enables interoperation between statically-typed and dynamic languages.
4. Enables fast execution of dynamic operations by supporting advance caching.
Which property do we set for UpdatePanel to refresh page on condition basis?

There is an UpdatePanel UpdateMode property,which we have to set to Conditional .

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

</asp:UpdatePanel>


It will not refresh the whole page.Only conditionly it will update portion of the page.
Which property should we set for UpdatePanel to refresh page unconditionally?

There is an UpdatePanel UpdateMode property,which we have to set to
Always
.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">

</asp:UpdatePanel>


By setting this property,the whole page will refresh every time.
Which control must be there on a page to work with AJAX controls?

ScriptManager control must be placed in a page to work with all AJAX controls.

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>


If we do not import ScriptManager control,then we can not work with AJAX controls.
What will happen,if we have more than one ScriptManager control in a Page?

We can not place more than one ScriptManager control on a Page.If we have more than one ScriptManager control,then at run time it will throw an error like

Only one instance of a ScriptManager can be added to the page.

It's clear that we can place more than one ScriptManager control.
What do we mean by Dictionary?

Dictionary is a collection which has key and value pair.
We can identify values with its keys.
For Example:-

Dim dict As New Dictionary(Of String, Integer)

Here String is our Key and Integer is our Value.
Can we have duplicate keys in Dictionary?

No we can not have duplicate keys in Dictionary.Because Dictionary have only unique keys.It will through run-time error if we add the same key into dictionary.
What will happen,if we run below code? Dim dict As New Dictionary(Of String, Integer) dict.Add("1", 100) dict.Add("1", 200)

When we run above code,then it will throw an error saying that

An item with the same key has already been added.

Because we know that Dictionary have Unique key,it can not be Duplicate.

Always check if key is duplicate:

if (!dict_names.ContainsKey("Key"))

{
//add keys into Dictionary
}

How to remove a particular key from Dictionary?

With the help of Remove method,we can remove a particular key from Dictionary.

For Example:-

dict.Remove("2");


Here 2 is my Key,so it will be removed from Dictionary.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories