亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

asp.net 在GridView EditItemTemplate模版里獲取控件

asp.net 在GridView EditItemTemplate模版里獲取控件

慕的地8271018 2018-12-06 21:12:31
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" CellPadding="4" ForeColor="#333333" GridLines="None" onrowediting="GridView1_RowEditing" DataKeyNames="com_id" onrowcommand="GridView1_RowCommand" onrowdatabound="GridView1_RowDataBound" onrowupdated="GridView1_RowUpdated" onrowcreated="GridView1_RowCreated"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:TemplateField HeaderText="編號"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text="Label"><%# Eval("com_num") %></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="公司名"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text="Label"><%# Eval("company_name") %></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="狀態"> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text="Label"><%# Eval("status") %></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:CommandField ShowEditButton="True" HeaderText="編輯" /> <asp:BoundField /> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> 我想在???RowDataBound事件里查找?EditItemTemplate里的控件 動態的給空間賦值? 可是怎么都找不到值 無語了 總是提示:未將對象因引用設置到對象的實力。 在網上的各種發放都試過了,每一個有用的? 請高人幫一下忙? ,小弟現在沒分了 ,有哪位高手愿意幫助一下, 謝謝了!
查看完整描述

2 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

要想?RowDataBound時間找到?EditItemTemplate里的控件,必須點擊編輯按鈕執行??

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
??????? {
??????????? GridView1.EditIndex = e.NewEditIndex;
??????????? LoadData();//此時綁定數據源時?RowDataBound事件函數能找到你的控件。
??????????? }

?private void LoadData()
??????? {
??????????? GridView1.DataSource = GridViewClass.ReadData();
??????????? GridView1.DataBind();
??????? }

??????? protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
??????? {
??????????? GridView1.EditIndex = -1;
??????????? LoadData();
??????? }

??????? protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
??????? {
??????????? if (e.Row.RowType == DataControlRowType.DataRow)
??????????? {

????????????? //要想找到控件必須點擊EDIT按鈕重新綁定DataSource

???????????? ? TextBox txt = (TextBox)e.Row.FindControl("TextBox1");
??????????????? if (txt != null)
??????????????? {
??????????????????? txt.Text ="ggggg";
??????????????? }
??????????? }
??????? }

查看完整回答
反對 回復 2019-01-21
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

模板列找控件關鍵FindControl

(e.Row.FindControl(要找的控件ID) as Textbox).Text

查看完整回答
反對 回復 2019-01-21
  • 2 回答
  • 0 關注
  • 1053 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號