Bulk fetching data in a DataGrid control template column

Source: Internet
Author: User
Datagrid|datagrid Controls | templates | Data bulk get data in the DataGrid control template column

In a DataGrid, you can usually only get data for each row individually, and to bulk get the data in the DataGrid control you must scan the controls for each template column to get the data.
I want to do the program is based on the number of different lines, the user input a number of data at a time, submitted after the system to automatically obtain batch data program.
The following program simply expresses the functionality that needs to be implemented

Test.aspx

..........

<asp:datagrid id= "Dgresult" runat= "Server" bordercolor= "#DEBA84" borderstyle= "None" cellspacing= "2"
Borderwidth= "1px" backcolor= "#DEBA84" cellpadding= "3" autogeneratecolumns= "False" >
<footerstyle forecolor= "#8C4510" backcolor= "#F7DFB5" ></FooterStyle>
<selecteditemstyle font-bold= "True" forecolor= "white" backcolor= "#738A9C" ></SelectedItemStyle>
<itemstyle forecolor= "#8C4510" backcolor= "#FFF7E7" ></ItemStyle>
<Columns>
<asp:boundcolumn datafield= "id" headertext= "column number" ></asp:BoundColumn>
<asp:templatecolumn headertext= "column name" >
<ItemTemplate>
<asp:textbox runat= "Server" enabled= "True" width= "id=" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "integer precision" >
<ItemTemplate>
<asp:textbox runat= "Server" enabled= "True" id= "Textbox1" width= "M" >20</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "decimal point Precision" >
<ItemTemplate>
<asp:textbox runat= "Server" enabled= "True" id= "Textbox2" width= "M" >10</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<pagerstyle horizontalalign= "Center" forecolor= "#8C4510" mode= "NumericPages" ></PagerStyle>


</asp:DataGrid>
<asp:button id= "Btnok" runat= "Server" text= "Submit" ></asp:Button>
......


Test.aspx.cs


private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
if (! IsPostBack)
Mfbind (DataSource ());
}

Private IList DataSource ()
{
DataTable dt=new DataTable ();
DataColumn dc=new DataColumn ();
dc. Columnname= "id";
dc. Datatype=system.type.gettype ("System.Int32");
dc. Readonly=true;
dc. Unique=true;
dc. Autoincrement=true;
dc. Autoincrementseed=0;
dc. Autoincrementstep=1;
Dt. Columns.Add (DC);

Dc=new DataColumn ();
dc. Columnname= "column name";
dc. Datatype=system.type.gettype ("System.String");
Dt. Columns.Add (DC);

for (int i=0;i<10;i++)
{
DataRow Dr=dt. NewRow ();
Dr[1]=i;
Dt. Rows.Add (DR);
}
session["Source" = DT;
Return dt. DefaultView;
}
private void Mfbind (IList dv)
{
This.dgresult.datasource= (DataView) DV;
This.dgResult.DataBind ();
}
private void Btnok_click (object sender, System.EventArgs e)
{
String tmpa=dgresult__ctl2_col1. Text;
TextBox txt;
ArrayList marr=new ArrayList ();
for (int i=0;i<10;i++)
{
Txt=new TextBox ();
txt= (TextBox) dgresult.items[i]. FindControl ("col");
Marr.add (txt. Text);
}
for (int i=0;i<marr.count;i++)
This.lblproblem.text+=marr[i]. ToString () + "; ";


}



In fact, such programs have commonality, through the DataGrid control can batch processing of data, especially in the process of deleting data and other operations to use and convenient, as long as the program's template column in the TextBox control to the CheckBox control or DropDownList control , scanning all the child controls can realize the bulk of the data quickly delete, modify, and other operations.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.