Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends


I Have an DataGrid Web Control in my .aspx page.

This Control have 4 columns the first one have a checkbox input.
the second one have only a text that show any information
the third column have only text and the number four column too.


Please see the code of my control in .aspx page:

ASP.NET
<asp:datagrid id="dtgDistribuidores" runat="server" Width="100%" CellSpacing="1" CssClass="datagrid" AutoGenerateColumns="False">
	<AlternatingItemStyle CssClass="rowAlt"></AlternatingItemStyle>
	<ItemStyle CssClass="row"></ItemStyle>
	<HeaderStyle CssClass="header"></HeaderStyle>
	<Columns>
		<asp:TemplateColumn HeaderText="ELEJIR">
			<ItemTemplate>
				<input type="checkbox" id="cbElejirEmpresa"  runat="server" title="Elejir" />
			</ItemTemplate>
		</asp:TemplateColumn>
		<asp:BoundColumn DataField="CODIGO_EMPRESA" HeaderText="Código" Visible="False"></asp:BoundColumn>
		<asp:BoundColumn DataField="IDENTIFICACION" HeaderText="RUC"></asp:BoundColumn>
		<asp:BoundColumn DataField="NOMBRE_EMPRESA" HeaderText="EMPRESA"></asp:BoundColumn>
	</Columns>
</asp:datagrid>



I have the c# code behind the aspx page and I need process the data for each row in the DataGrid component


C#
private void btnGuardar_Click(object sender, System.EventArgs e)
{
    /*INSERT YOUR CODE HERE*/			
}


Please I need your help, Please tell me how I can:

1) Get the data from the component for each row in a for cycle
2) I want to precess the rows that are checked in the DataGrid Web control How I can do this.


Thanks in advance

Leonardo Ayala R.
Posted
Updated 15-Jan-14 9:45am
v3

First off, google these thing bro...



foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
            
            foreach (DataGridViewCell dc in dr.Cells)
            { 
               //dc is each cell, take it from there
            }

        }
 
Share this answer
 
v2
Comments
leocode7 17-Jan-14 9:20am    
thanks my friend :)
It was just a search away.
Quote:
Get the data from the component for each row in a for cycle


Answering your first query , it can be done multiple ways such as using FindControl while iterating through the Gridview Row Collections or by using cells property.

http://forums.asp.net/t/1893452.aspx?loop+through+all+rows+in+a+gridview+and+get+the+contents[^]

Quote:
I want to precess the rows that are checked in the DataGrid Web control How I can do this


Refer below link to get the selected rows

http://www.aspsnippets.com/Articles/GridView-with-CheckBox-Get-Selected-Rows-in-ASPNet.aspx[^]

Hope this helps
 
Share this answer
 
Comments
leocode7 17-Jan-14 9:20am    
Yeah! you have reason, I implemented in a few words the follow code:

asp:
<asp:DataGrid ID="MyDataGrid" AutoGenerateColumns="false" runat="server"
<asp:CheckBox ID="cbRows" runat="server"/>

c#:
foreach (DataGridItem item in MyDataGrid.Items)
//////
((CheckBox)item.Cells[6].FindControl("cbRows")).Checked
/****************************************************************/

Thanks a lot for your help
JoCodes 17-Jan-14 13:00pm    
You are welcome friend. ..glad to hear your issue is fixed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900