Solved

Gridview Databound Control

Posted on 2007-11-30
4
3,036 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 250 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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