C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Gridview Colspan (Code please)


Posted Date: 16 Dec 2008      Posted By: Binu Kumar      Member Level: Silver     Points: 1   Responses: 1



hi friends,

I want to span 12 columns of a gridview in Edit mode
How can i do this please any soln...

thanks






Responses

Author: Amit Shah    16 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

The first task is the create a GridView. Check out the html code to create the GridView control:

<asp:GridView ID="gvUsers" AutoGenerateColumns="false" runat="server" OnRowDataBound="gvUsers_RowDataBound">

<Columns>

<asp:TemplateField HeaderText="User ID">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="First Name">

<ItemTemplate>

<asp:Label ID="lblFirstName" Visible='<%# !(bool) IsInEditMode %>' runat="server" Text='<%# Eval("FirstName") %>' />

<asp:TextBox ID="txtFirstName" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Eval("FirstName") %>' />

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Last Name">

<ItemTemplate>

<asp:Label ID="lblLastName" Visible='<%# !(bool) IsInEditMode %>' runat="server" Text='<%# Eval("LastName") %>' />

<asp:TextBox ID="txtLastName" Visible='<%# IsInEditMode %>' runat="server" Text='<%# Eval("LastName") %>' />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>


As, you can see in the html code that both my label and the textbox are in the ItemTemplate and there visibility depends on the IsInEditMode property. Now, let's check out the code behind:

private bool isEditMode = false;

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

BindData();

}

}

private void BindData()

{

string connectionString = "Server=localhost;Database=School;Trusted_Connection=true";

SqlConnection myConnection = new SqlConnection(connectionString);

SqlDataAdapter ad = new SqlDataAdapter("SELECT UserID, FirstName, LastName FROM Users", myConnection);

DataSet ds = new DataSet();

ad.Fill(ds);

gvUsers.DataSource = ds;

gvUsers.DataBind();

}

// This method will put the GridView in the edit mode

protected void Button1_Click(object sender, EventArgs e)

{

isEditMode = true;

BindData();

}

protected bool IsInEditMode

{

get { return this.isEditMode; }

set { this.isEditMode = value; }

}

protected void Button2_Click(object sender, EventArgs e)

{

isEditMode = false;

BindData();

}



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Extract metadata/content from pdf & doc
Previous : TabContainer and validation
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use