Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Gridview Databound Control

Posted on 2007-11-30
4
Medium Priority
?
3,060 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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