Grid View should have all control.

Posted by Mahe under ASP.NET on 7/4/2012 | Points: 10 | Views : 1077 | Status : [Member] | Replies : 7
Hi All,

Please provide me the code for Grid View in asp.net 3.0 and above, where in the Grid view should have all control in each column.

Thanks&Regards,
Mahe




Responses

Posted by: Premalatha on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
Gets a collection of DataControlField objects that represent the column fields in a GridView control.

Premalatha
Software Engineer

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

void CustomersGridView_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{

// Cancel the paging operation if the user attempts to navigate
// to another page while the GridView control is in edit mode.
if (CustomersGridView.EditIndex != -1)
{
// Use the Cancel property to cancel the paging operation.
e.Cancel = true;

// Display an error message.
int newPageNumber = e.NewPageIndex + 1;
Message.Text = "Please update the record before moving to page " +
newPageNumber.ToString() + ".";
}
else
{
// Clear the error message.
Message.Text = "";
}

}

void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e)
{
// Clear the error message.
Message.Text = "";
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView PageIndexChanging Example</title>
</head>
<body>
<form id="form1" runat="server">

<h3>GridView PageIndexChanging Example</h3>

<asp:label id="Message"
forecolor="Red"
runat="server"/>

<br/>

<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowpaging="true"
autogenerateeditbutton="true"
datakeynames="CustomerID"
onpageindexchanging="CustomersGridView_PageIndexChanging"
onrowcancelingedit="CustomersGridView_RowCancelingEdit"
runat="server">

<pagersettings mode="Numeric"
position="Bottom"
pagebuttoncount="10"/>

<pagerstyle backcolor="LightBlue"/>

</asp:gridview>

<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>

</form>
</body>
</html>

Premalatha
Software Engineer

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahe on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Premalatha,

I want to have Gridview, where in each column should distinct control.
Lets say for example,

Col1 contains Check box
Col2 contains Radio button
Col3 contains Button
Col4 contains Bound field value
...
...
and so on.




Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Just look it once

http://forums.asp.net/t/1788372.aspx/1?MENU+GRIDVIEW+How+to+Select+DISTINCT+in+one+column+and+return+ALL+for+different+column

Premalatha
Software Engineer

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Mahe,

This is sample code for ASPX Page, currently it contains , Radio Buttons, Checkboxes, Textbox, Image Label etc.

<asp:GridView ID="GridView1" runat="server" AllowPaging="true" 

AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing" AutoGenerateEditButton="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate><b>User Name</b> </HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblUName" runat="server" Text='<%#Eval("UserName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<b>Gender</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblGender" runat="server" Text='<%#Eval("UserGender") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButton ID="RadioMale" runat="server" GroupName="Gender" Text="Male" />
&nbsp; &nbsp;
<asp:RadioButton ID="RadioFemale" runat="server" Text="Female" GroupName="Gender" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>

<Columns>
<asp:TemplateField>
<HeaderTemplate>
<b>Profile Picture</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Image ID="ProfileImage" runat="server" ImageUrl='<%#Eval("ImagePath") %>' Width="150px"
Height="120px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate><b>
<asp:CheckBox ID="chkSelectAll" runat="server" Text="Select All" /></b></HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" Text="Select" /></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Make your Code as requirement.


John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
@Premalatha ,

Please format your Code as code in Post. To do so, First Paste Code in Edit Textbox and then Select Code, Then Click Code in toolbar of Edit screen. This will format your code.


John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Plz refer this url. it will help u

http://www.codeproject.com/Articles/50540/GridView-Event-Handling

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response