DataGrid在dropdownselectedindex值更改事件中获取特定行
本文关键字:获取 事件 dropdownselectedindex DataGrid | 更新日期: 2023-09-27 18:23:53
我正在做一个小项目。在中使用Datagrid
<asp:DataGrid ID="dgShowTiming"
runat="server"
AutoGenerateColumns="false"
OnItemCreated="dgShowTiming_ItemCreated">
<Columns>
<asp:TemplateColumn HeaderText="HOUR">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingsHours"
runat="server"
CssClass="field1"
DataSource="<%#Hour()%>"
DataTextField="Hours"
DataValueField="Hours">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="MINUTE">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingsminutes"
runat="server"
CssClass="field1"
DataSource="<%#Minute()%>"
DataTextField="Minutes"
DataValueField="Minutes">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="AM/PM">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingAMPM"
runat="server"
CssClass="field1"
onchange="GetCountryDetails()">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingDescription"
runat="server"
DataSource="<%#Description()%>"
DataTextField="ShowTimeDesc"
DataValueField="ShowTimeDescID"
CssClass="field1">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Tax Details">
<ItemTemplate>
<asp:Label ID="lblRowID"
runat="Server"
Text="View"
Style="cursor: pointer;"
onclick="FilmTaxDetailsOpen(this);"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
所以现在我在这个网格中的问题是,我必须在选择下拉列表的数字更改值ddlShowTimingAMPM时,我想将描述更改为NOON或上午或晚上。。我面临的问题是如何获取所选的3个下拉列表的值,在此基础上只更改描述。
尝试这个100%工作和测试的
一旦找到行,就可以从该行中找到该行中的所有控件。您可以同样应用于其他DropDownList
,并为所有DropDownList
设置AutoPostBack="true"
protected void ddlShowTimingsHours_OnSelectedIndexChanged(object sender, EventArgs e)
{
DataGridItem item = (DataGridItem)((DropDownList)sender).Parent.Parent;
DropDownList ddlShowTimingsHours = (DropDownList)item.FindControl("ddlShowTimingsHours");
DropDownList ddlShowTimingsminutes= (DropDownList)item.FindControl("ddlShowTimingsminutes");
DropDownList ddlShowTimingAMPM= (DropDownList)item.FindControl("ddlShowTimingAMPM");
}