CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > visual_studio.vs_2005_web_application_projects Tags:
Item Type: Date Entered: 6/13/2007 5:21:38 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 2 Views: 243 Favorited: 0 Favorite
3 Items, 1 Pages 1 |< << Go >> >|
"kaustubhbhat"
NewsGroup User
How to generate fixed number of rows in a GridView?6/13/2007 5:21:38 AM

0

Hi All,

 I am facing a small problem in my Web Application.

I have a textbox and i'll be entering any numaric value in it. for ex. "2";

I also have a gridview with 2 template coloumns ans 1 unbound item.

Now based on the value entered in the above textbox, i want to generate that many number of rows in that grid. How do i do that?

Please help me out. 


 

"Benson Yu - MS
NewsGroup User
Re: How to generate fixed number of rows in a GridView?6/14/2007 8:45:49 AM

0

Hi kaustubhbhat,

The GridView control renders to client is a HTML table. So we can operate it on the client side. However, please note the Gridview will render every postback, so all the change will be restored. The following code is for your reference. I hope it is helpful to you.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function SetNumberOfRows(textbox)
        {
            var number = Number(document.getElementById('Text1').value);
            var table = document.getElementById('GridView1');
            if (table.rows.length > number)
            {
                for(var i=table.rows.length; i>number;)
                {
                    table.deleteRow(--i);
                }
            }
            else
            {
                for(var i=table.rows.length; i<number; i++)
                {
                    var row = table.insertRow();
                    var cell = row.insertCell();
                    cell.innerText = 'null';
                    cell = row.insertCell();
                    cell.innerText = 'null';
                }
            }
           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <br />
        <input id="Text1" style="position: static" type="text" />
        <input id="Button1" onclick="SetNumberOfRows()" style="position: static" type="button"
            value="button" /></div>
    </form>
</body>
</html>

****************** code behind file
        DataTable myTable;
        protected void Page_Load(object sender, EventArgs e)
        {
            myTable = new DataTable();
            myTable.Columns.Add("ID", typeof(Int32));
            myTable.Columns.Add("Name", typeof(String));
            myTable.Rows.Add(1,"aaa");
            myTable.Rows.Add(2, "bbb");
            myTable.Rows.Add(3, "ccc");
            GridView1.DataSource = myTable;
            GridView1.DataBind();
        }

 


Sincerely,
Benson Yu
Microsoft Online Community Support

Please remember to click ?Mark as Answer? on the post that helps you, and to click ?Unmark as Answer? if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
"kaustubhbhat"
NewsGroup User
Re: How to generate fixed number of rows in a GridView?7/9/2007 8:52:21 AM

0

 Thanks a lot benson. It really helped me a lot. Looking forward to your help in future.

Thanks and take care. 

3 Items, 1 Pages 1 |< << Go >> >|


Free Download:













querystring parameters into global.asax

public class global - need help

website url problem...

changing string to numerical value of 0 when no text is entered

displaying alphabets in asp.net2.0

fckeditor

dynamic linkbutton javascript err - object doesn't support property or method

calendar days only selectable from today

compiler error message: bc30456

server.mappath

need help extracting text from string

how do i access variable defined in sub page_load

help converting vb to c#

need asp.net book for advanced programmer

code behind errors

many failed attempts please help

attribute "id" vs control.id propertry

passing parameters

sql error 290

generate pie / bar charts

how to generate the diagram/graph?

type system

select command for repeater needs to be dynamic

inserting .avi files

adding product options

accessing a declared namespace that is not in a child directory

advice for begginer...

some basic questions, will work for food

where is cookie stored in this code?

problem navigating backword

best .net sites??

not a valid path. make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

ms sql script

web.config for applications in subdirectory

modal dialog form user control

my internet isn't staying connected when i use any programs that use the internet............please help

webusercontrol and setting value directly in form

create dynamic image to prevent bots on registration

multiple formview inserts

xml file cannot be display error

how to use "form" to pass parameters from a webpage to another webpage?

problem with session variable after postback

what happen at compile time in c#

dll file problem used in "custom control"

regarding reports

creating a database searchable by zip code

iam learner of asp.net i want answer for my doubts

working with dates

custom user interface

connectionstring code question

   
  Privacy | Contact Us
All Times Are GMT