Datagrid plus drop-down list dropdownlist and dropdownlist

Source: Internet
Author: User

Datagrid plus drop-down list dropdownlist and dropdownlist

Code in the datagrid:

<Asp: datagrid id = "dgList" runat = "server" ItemStyle-HorizontalAlign = "Center" HeaderStyle-HorizontalAlign = "Center" HorizontalAlign = "Center" PageSize = "5" AutoGenerateColumns = "False" gridLines = "Horizontal" CellPadding = "1" BackColor = "White" BorderWidth = "1px" BorderStyle = "None" BorderColor = "# E7E7FF" Width = 100% OnItemDataBound = "Maid itemdatabound"> <FooterStyle ForeColor = "# 4A3C8C" BackColor = "# B5C7DE"> </FooterStyle> <SelectedItemStyle Font-Bold = "True" ForeColor = "# F7F7F7" BackColor = "# 738A9C"> </SelectedItemStyle> <AlternatingItemStyle BackColor = "# F7F7F7"> </AlternatingItemStyle> <ItemStyle placement = "Center" ForeColor = "# 4A3C8C" BackColor = "# E7E7FF"> </ itemStyle> <HeaderStyle Font-Bold = "True" HorizontalAlign = "Center" ForeColor = "# F7F7F7" BackColor = "# 4A3C8C"> </HeaderStyle> <Columns> <asp: templatecolumn HeaderText = "status"> <itemtemplate> <asp: dropdownlist id = "ItemDropDown" runat = "server" AutoPostBack = "true" OnSelectedIndexChanged = "DropDown_SelectedIndexChanged"/> </itemtemplate> </asp: TemplateColumn> <asp: templateColumn> <ItemTemplate> <asp: Button id = "SaveButton" Visible = "false" runat = "server" CommandName = "save" Text = "save"> </asp: button> </ItemTemplate> </asp: templatecolumn> <PagerStyle ForeColor = "# 4A3C8C" BackColor = "# E7E7FF" Mode = "NumericPages"> </PagerStyle> </asp: datagrid>
Private void InitializeComponent () {this. dgList. itemCommand + = new System. web. UI. webControls. dataGridCommandEventHandler (this. dgList_ItemCommand);} protected void maid (object sender, DataGridItemEventArgs e) {if (e. item. itemType = ListItemType. alternatingItem | e. item. itemType = ListItemType. item) {string [] options = {"", "notified", "Change email", "unable to contact", "cancel Merchant"}; DropDownList li St = (DropDownList) e. item. findControl ("ItemDropDown"); list. dataSource = options; list. dataBind (); TableCell cell = list. parent as TableCell; DataGridItem item = cell. parent as DataGridItem; int index = item. itemIndex; list. selectedValue = item. cells [1]. text ;}} protected void DropDown_SelectedIndexChanged (object sender, EventArgs e) {DropDownList list = (DropDownList) sender; TableCell cell = li St. parent as TableCell; DataGridItem item = cell. parent as DataGridItem; int index = item. itemIndex; string content = item. cells [12]. text; // DropDownList down = (DropDownList) item. findControl ("ItemDropDown"); string checkState = list. selectedValue. trim (); object obj = item. cells [13]. findControl ("queryButton"); if (obj! = Null) {Button lb = (Button) obj; lb. visible = true; // The Save button is displayed in the dynamic drop-down list} private void dgList_ItemCommand (object source, System. web. UI. webControls. dataGridCommandEventArgs e) {string spid = e. item. cells [2]. text. trim (); string crt_etime = e. item. cells [8]. text. trim (); string state = e. item. cells [12]. text. trim (); try {if (e. commandName = "save ");.............................. // Save} catch (Exception eSys) {WebUtils. ShowMessage (this. Page, "failed to save data! "+ ESys. Message );}}

 


3. How to add a column like this in the DataGrid: A DropDownList column, and the DropDownList of each row can be

Insert a template column in The DataGrid
<Asp: TemplateColumn HeaderText = "drop-down box column">
<ItemTemplate>
<Asp: dropdownlist id = "ddlCopyFileQty" runat = "server" Width = "52px">
<Asp: ListItem Value = "0"> 0 </asp: ListItem>
</Asp: dropdownlist>
</ItemTemplate>
<HeaderStyle Width = "60px"/>
</Asp: TemplateColumn>
Your question says "and every row's DropDownList can be used" is still incomplete. I guess whether to obtain the DropDownList of each row for value assignment or value operation:
Foreach (DataGridItem dt in dgInfoList. Items)
{
DropDownList ddlCopyFileQty = (DropDownList) dt. Cells [3]. FindControl ("ddlCopyFileQty ");
DdlCopyFileQty. SelectedValue = dt. Cells [6]. Text;
}
 
How can I dynamically insert data in the drop-down box set in the DATAGRID in aspnet?

Use Template
Add data to dd in itembound event
 

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.