Solved

Gridview Databound Control

Posted on 2007-11-30
4
2,984 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now