Populate row by row data in gridview

Hi ,

How to populate the data row by row in grid view.

For example:

I wirte this code in .aspx page

<asp:TemplateField HeaderText="COC Date of Calibration">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# COC_Date("strDate") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# COC_Date("strDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

The TemplateField will call the function from aspx.vb

Function COC_Date(ByVal strDate As String) As Date

  For Each dr As DataRow In tempTbl.Rows  ' I open very row of the data, get the data primary key then retrieved the strDate. Because the strDate is not in database

if .... the

strDate=....

else

strDate=.....

end if

 ' how can I populate the strDate in gridView row by row

' i think we need to do some coding at here, to populate it

end function

 

For example, in VB we can populate the data in Excel by this code:

objWB.Cells(a, 1) = strDate

So i need to do same thing to populate in grid view.

Any one have a suggestion????

looking for your expertise.

Thanks....

0
gtcr
10/31/2008 12:05:49 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
623 Views

Similar Articles

[PageSpeed] 47

 

 you can call a function

 

 

<asp:TemplateField >
 
<ItemTemplate>

       <asp:TextBox ID="txtDate" runat="server"   Text =  <%# changevaluue(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "yourdatecolumn")%>'/>
  </ItemTemplate>
</asp:TemplateField>


then in code behind

 

public string GetVisible(datetime dt)
{
check the conditions and return the value
}

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
10/31/2008 12:30:15 PM

Thanks for your reply.

But i cannot get you....

U mean i have to write Text =  <%# changevaluue(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "yourdatecolumn")%>'/> instead of Text='<%# COC_Date("strDate") %>'

If I change the code as you suggest, then i cannot calll function COC_Date and cannot get strDate....

Did you have any suggest that i can continue my code to populate the strDate in Function COC_Date

Function COC_Date(ByVal strDate As String) As Date

  For Each dr As DataRow In tempTbl.Rows  ' I open very row of the data, get the data primary key then retrieved the strDate. Because the strDate is not in database

if .... the

strDate=....

else

strDate=.....

end if

 ' how can I populate the strDate in gridView row by row

' i think we need to do some coding at here, to populate it

end function

0
gtcr
11/1/2008 1:53:39 AM

Can I write the code in this way.

Function COC_Date(ByVal strDate As String) As Date

  For Each dr As DataRow In tempTbl.Rows  ' I open very row of the data, get the data primary key then retrieved the strDate. Because the strDate is not in database

if .... the

strDate=....

else

strDate=.....

end if

Dim i as integer 

GridView.Row(i).Cells(9).Text=strDate

end function

0
gtcr
11/1/2008 2:29:47 AM

Hi gtcr ,

gtcr:
Text='<%# COC_Date("strDate") %>'

The return value of COC_Date function will be set to Text property of TextBox2 in each line. But if you want to set value for each row of GridView , usually we do not put code here. I will put code in PreRender event handler of Gridview. Something like this:

    protected void GridView1_PreRender(object sender, EventArgs e)
    {
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            Label lbl = this.GridView1.Rows[i].FindControl("Label1") as Label;
            lbl.Text = "test";
        }
    }
  
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="countryid"
            DataSourceID="SqlDataSource1" OnPreRender="GridView1_PreRender" Width="304px">
            <Columns>
                <asp:BoundField DataField="countryid" HeaderText="countryid" ReadOnly="True" SortExpression="countryid" />
                <asp:BoundField DataField="countryname" HeaderText="countryname" SortExpression="countryname" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
 

Samu Zhang
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.
0
Samu
11/4/2008 3:43:42 AM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

Accessing GridView Data Row By Row
guys i have just started with asp.net i have a basic doubt, i have created a SQL datasource and a gridview associated with it now what i need to do is get all the data from my database n modify it further, for this i need to access each row of the gridview any ideas on how to do so? foreach(GridViewRow row in GridViewName.Rows) { you can interate like this..  }Better Post your code before asking some thing, some one. So that person helping u will understand u r problem ClearlyYahoo IM : dotnetrulerI am trying to keep Frequently Asked Questions in my blog  When u enable show...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

copy data from excel row to gridview row
Hi All, I need to copy data from excel to asp.net gridview. I have to select a row and press Ctrl+C to copy from excel, then I have to paste it in Gridview. Thanks in advance. I dont think you can Copy and Paste data from Excel to Gridview.But you can export data from Excel to GridView control, please check the below articles.http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspxhttp://www.aspdotnetcodes.com/SqlbulkCopy_Data_Transfer.aspxMarking a Reply as 'Answered', not only GAIN us some POINTS, but it also HELP others to find RIGHT solution....

Detecting Footer Row vs Data row in a gridview
Hello, I am trying to run validation controls using page pre-render in vb for a gridview where I have the insert in the footer of the gridview and updates in the individual rows. The Prerender will highlight the controls which have failed the validation. My problem is that when the Page prerender fires, I cannot figure out how to get the controls depending on whether it is an insert from the footer, or an update from a regular row in the Gridview. The insert from the footer works well, but the update from a Gridview row does not. Also I have got a formview in the gridviews empty templat...

Gridview row editing fields based on row data
Is there a way to change row editable fields in a databound gridview based on the rows data. For example letting a user edit all his and his fellows fields but preventing him from changing specific fields in his boss data on the same gridview? Help will be great fully appreciated. Thanks If I understand what you are saying is that you want to only allow a user to Edit certain rows within the GridView. If so, yes, you certainly can do this. What I would do is hide/display the Edit Button for a row based on the user's role or permissions. This can easily be done via the RowDataBound e...

Multiple grid rows per Data row in GridView
I have a dataset that is binded to a gridview. The dataset has 5 fields and a description. I want to display 1 row for the 5 short fields and 1 row underneath it for the description. (per record)   For example: ID Name  Surname Field3 Field 4 1   John     Smith      blah    blah     This is the long description for  John Smith spanning 5 cells 2   Peter    Parker     blah    blah     This is t...

ADO.net problem: i can not view image data for the rest of my table rows except the image for the first row but i can read all the other non image fields for all rows.
Hi i have a table with the following fields imgid............int imgdata........image imgtitle.........varchar(max) imgType........varchar(max) imgLength.....bigint incident_id.....int i have no problem with uploading the image but viewing the uploaded image(s) in a gridview has caused me great pain. The probelm is i have two pages. page1 grabs the image to display and page2 has a gridview that displays the grabed image. I wanted to have an sql statement like SELECT * FROM mytable WHERE incident_id=someValue. IF i have 5 records in this table and i view page2 ...

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

Gridview row 0 selected, but data for row+1 is displayed... ??
Hello. Here's a rather interesting dilemma--hopefully easy to solve? Though I'm stumped for the moment, so any help will be greatly appreciated. I have a gridview with master records listed. The records are acquired using L2S and a sproc that applies Row_Number() to the results for custom paging. The resultset looks fine. It binds to the gridview as expected (displaying data for rows 1 through 5). Each master record has a "select" column to allow the user to select which master record to display in the detail record view. When select is clicked, the child records are&...

How to get the data of a particular row in gridview without editing that row.
I have a gridview in a page in that ihave hyperlink as one column on click of that i want to go next page with the data present in that corresponding row. How shell i read the data from grid view for that pirticular row.On which event i can get the data. HI, the row that is selected should be passed into a string or an array or in sessionsthis can be done through this code  protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        Label _lbl = new Label();      &...

add data from multiple rows in table to one row in gridview
 heya is there any way of adding data from multiple rows in table to one row in gridview. eg. ipc                 column 1 ,            2 ,                       3,                 4  1,    11111                 33                  &nbs...

Gridview row click event fires, when clicking on controls within row.
I have a gridview control and I have added  a row click event which causes a post back. e.Row.Attributes.Add("onClick", this.Page.ClientScript.GetPostBackEventReference(this, "Select$" + e.Row.RowIndex.ToString()));  When the user clicks the row, i bind some data to a checkbox list, showing a uers a list of options they have chosen. All good so far. I also have a edit button for each row. When the row is in edit mode i display a checkbox and textbox. Problem is when i click on the textbox or the checkbox, it causes the row click event to fire. Any ida...

Web resources about - Populate row by row data in gridview - asp.net.presentation-controls

Facebook Fans Populate National Car Rental Playlist
... its Facebook fans are listening to, so the company teamed up with music-streaming service Songza to allow users who like its page to help populate ...

Facebook Launches Integrations With Spotify, Netflix and More to Populate the Ticker with Playable Content ...
A wide variety of media partners and news publishers have partnered with Facebook to allow uses to publish content to the site that can be immediately ...

Perish the populate thought
Population size and growth, resources and climate change are obviously linked.

Islamic State militants raping thousands of women to populate caliphate, Iraqi official claims
ISLAMIC State fighters are reportedly raping thousands of women in Iraq and Syria to mass-produce spawn who&#8217;ll follow in their footsteps. ...

Researchers craft bot to populate Wikipedia with gene data
In order to help make Wikipedia a better source of information for biologists …

Are Chuck Schumer and Steve Israel Working To Populate Congress In The Image Of Scoop Jackson?
History lesson: In 1972 and again in 1976, the Beltway's conservative Democratic Establishment had found its man. The preferred candidate of ...

Extreme Shrimps Could Possibly be Sent to Populate Europa, NASA Reports
Rimicaris hybisae live on the edges of hydrothermal vents 7,500 feet underwater whose temperatures reach 750 degrees Fahrenheit.

Glowing robotic tentacles populate this Petting Zoo
(Credit: Minimaforms) If you swing by the Petting Zoo in Orleans, France, don't expect to see goats. The robotic "pets" that reside there hang ...

CNN.com - Millionaires populate U.S. Senate - Jun. 13, 2003
The U.S. Senate showed once more why it's sometimes called the millionaires' club.

Pokémon 2DS bundles soon to populate Australian store shelves
Australian gamers who have yet to pick up Pokémon X and Pokémon Y will be able to purchase one of two new Nintendo 2DS system bundles on June ...

Resources last updated: 12/23/2015 10:29:15 AM