我有一个下拉列表。在更改下拉列表的索引时,我在 asp.net gridview 中填充了一行。
每当下拉列表值发生变化时,我不想刷新整个网格视图,而是将新行附加到网格视图中。
有谁知道怎么做?我的代码如下:
aspx:
<table>
<tr>
<td>
<div>
<asp:Label ID="lblClient" runat="server" Text="Client :" CssClass="label" ForeColor="Black"></asp:Label>
<asp:DropDownList ID="ddlClient" runat="server" AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged">
<asp:ListItem Text="ALL" Value="0"></asp:ListItem>
</asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvMainLog" runat="server" Visible="true" AllowSorting="True" AutoGenerateColumns="False"AllowPaging="true">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<div id='<%# "myRow" + Container.DataItemIndex %>'>
<asp:Literal ID="ltId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Instruction")%>'></asp:Literal>
<img src="../Images/KnobRed.png" onclick='<%# "deleteRow(\"myRow" + Container.DataItemIndex+"\")" %>'/> </div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
aspx.cs
protected void ddlClient_SelectedIndexChanged(object sender, EventArgs e)
{
gvMainLog.DataSource = GetDealerSetupUtilityByClientId(1,1);
gvMainLog.DataBind();
}
javascript
<script type="text/javascript">
function deleteRow(rowId) {
$("#" + rowId).remove();
}
</script>