您好我有一個GridView和一個文本框放置在Ajax更新面板中。如何在GridViewRowCommand事件的同一頁面上更新文本框的文本
<asp:UpdatePanel ID="UpdatePanelAdmissionDefaultSettings" runat="server">
<ContentTemplate>
<asp:GridView ID="GridViewMeritDetails" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#5C5C5C" BorderStyle="Solid" BorderWidth="1px"
CellPadding="4" ForeColor="Black" CssClass="MeritGridStyle"
onrowdatabound="GridViewMeritDetails_RowDataBound"
onrowcommand="GridViewMeritDetails_RowCommand">
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:BoundField HeaderText="Field Name" DataField="MeritField" />
<asp:BoundField HeaderText="Field ID" DataField="MeritFieldID" />
<asp:ButtonField CommandName="edit" HeaderText="Edit" Text="Edit" />
<asp:ButtonField CommandName="delete" HeaderText="Delete" Text="Delete" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:TextBox ID="TextBoxMeritFieldName" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
我的問題是,當我點擊GridView的編輯按鈕,我想在文本框中選定行中顯示在一個單元格的值:
源如下。我已經給出了代碼在GridView RowCommand事件中顯示它。但它不起作用。
這裏是後面的代碼:
protected void GridViewMeritDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
int iRowIndex = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "edit")
{
TextBoxMeritFieldName.Enabled = true;
TextBoxMeritFieldName.Text = GridViewMeritDetails.Rows[iRowIndex].Cells[0].Text.Trim();
}
else if (e.CommandName == "delete")
{
//Add code to delete merit field
}
}
當我調試,控制進入RowCommand併到達線
TextBoxMeritFieldName.Text = GridViewMeritDetails.Rows[iRowIndex].Cells[0].Text.Trim();
但文本不顯示在頁面上。我錯過了什麼?
我嘗試這樣做。但它沒有幫助。感謝您付出努力幫助我。 – 2012-08-09 06:42:09
使用UpdateMode =「有條件」而不是Mode,我已更正了我的答案。 – Adil 2012-08-09 13:01:23