?
Solved

Gridview Databound Control

Posted on 2007-11-30
4
Medium Priority
?
3,051 Views
Last Modified: 2013-11-26
I have a Gridview with databound columns.  When the Gridview is displayed the headers for the databound columns headers appear, along with any data, but the textbox controls do not. The controls seem to be created dynamically when the user selects the edit button.

I am looking for a way to shorten the width of several of these dynamically created textboxes.  

Does anyone have a clue as to how this could be done?
0
Comment
Question by:ExecQ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20383976
Does the column have an EditItemTemplate defined?

Bob
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20384476
make sure your table has and index or primary key of somesort, refresh the grid...
0
 
LVL 10

Accepted Solution

by:
digitalZo earned 1000 total points
ID: 20387144
You have to use EditItemTemplate for that.
 <asp:templatefield headertext="Field1">
 
        <itemstyle width=60% wrap=True />
 
        <itemtemplate>
           <asp:label runat="server" 
              id="Field1"
              text='<%# Eval ( "Field1" ) %>' />
        </itemtemplate>
 
        <edititemtemplate>
           <asp:textbox textmode="singleline" runat="server" MaxLength=2
              id="Field1" rows=5 width=40%
              text='<%# Bind ( "Field1" ) %>'  />
        </edititemtemplate>
        
     </asp:templatefield>
       

Open in new window

0
 

Author Comment

by:ExecQ
ID: 20397182
Yes, the column does have a EditTemplate Field.

<asp:GridView id="gv_dc" runat="server" OnDataBound="gv_dc_DataBound" DataKeyNames="ClassID,StudentID,ClassMonth,ClassPeriodID" DataSourceID="sql_contactHours" CellPadding="3" BorderWidth="1px" BorderStyle="Dotted" BackColor="White" AllowSorting="True" Width="798px" AllowPaging="True">
<Columns>
    <asp:TemplateField ShowHeader="False">    
<EditItemTemplate>
    <asp:Button id="Button1" runat="server" Text="Update" CommandName="Update" CausesValidation="True"></asp:Button><br />
    <asp:Button id="Button2" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="False"></asp:Button>
</EditItemTemplate>
<ItemTemplate>
    <asp:Button id="Button1" runat="server" Text="Edit" CommandName="Edit" CausesValidation="False" Width="39px"></asp:Button>
</ItemTemplate>      
    </asp:TemplateField>
</Columns>
<HeaderStyle CssClass="font_tab"></HeaderStyle>
</asp:GridView>

The table does have a primary key field and index, but it also is created dynamically.

Here is code to create the textboxes when the grid loads:

System.Web.UI.WebControls.TextBox tb = new System.Web.UI.WebControls.TextBox();
tb.ID = "day_" + ClassDays[i].ToString();
tb.ControlStyle.Width = 50;
tb.Width = 5;

Neither of the width properties work.  This code is placed within a for loop that runs after the sql statement has been formulated.  It provides the grid with the number of columns, depending on the sql statement.  There are no set number of columns at anytime for the grid, so I don't think I can specify an edittemplate in the way digitalZo is commenting...
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question