将网格视图列值插入到文本框和按钮控件的下拉列表中

Insert Grid View column value into Textbox and dropdown on button control

提问人:Nits Patel 提问时间:11/1/2019 最后编辑:Nits Patel 更新时间:11/1/2019 访问量:383

问:

As i mention in image my output should be on Proceed button event

我想将gridview列值填充到给定的控件中 比如项目标题值、在项目标题文本框中填写、问题 ID、在所选问题下拉列表中填写等等......在按钮点击时,甚至

我已将控件名称作为

项目标题为 txtProjectTitle,

selectProblem ID 为 ddlSelectProblem,

Project_Start_Date为 txtProjectStartDate,

Project_Target_Date为 TextBox1,

gridview 作为 GrdTemp,

作为Button2_Click的 Procedd 按钮 ASPX 代码:

     [![<asp:GridView ID="GrdTemp" runat="server" Style="width: 100%; text-align: center" class="table table-striped table-bordered" AutoGenerateColumns="false">
         <Columns>
         <asp:TemplateField HeaderText="S.No." HeaderStyle-Width="5%">
         <ItemTemplate>
         <%# Container.DataItemIndex + 1 %>
         </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="ID" Visible="false">
         <ItemTemplate>
         <asp:Label runat="server" Text='<%# Bind("ID") %>' ID="lblID"></asp:Label>
         </ItemTemplate>
         </asp:TemplateField>

         <asp:TemplateField HeaderText="Project Title">
         <ItemTemplate>
         <asp:Label runat="server" Text='<%# Bind("Project_Title") %>' ID="lblID"></asp:Label>
         </ItemTemplate>
         </asp:TemplateField>
<asp:TemplateField HeaderText="Problem ID">
         <ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Problem") %>' ID="lblID"></asp:Label>
         </ItemTemplate>
         </asp:TemplateField>
<asp:TemplateField HeaderText="Project Start Date">
        <ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Project_Start_Date") %>' ID="lblID</asp:Label>
        </ItemTemplate>
        </asp:TemplateField>
<asp:TemplateField HeaderText="Project Target Date">
       <ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Project_Target_Date") %>' ID="lblID"></asp:Label>
        </ItemTemplate>
        </asp:TemplateField>
</Columns>                                                            </asp:GridView>][2]][2]

C# 代码:

 protected void Button2_Click(object sender, EventArgs e)
        {
            GridViewRow row = (sender as Label).NamingContainer as GridViewRow;
            TextBox txtProject = row.FindControl("txtProjectTitle") as TextBox;
            txtProject.Text = Convert.ToString((row.Parent.Parent as GridView).DataKeys[row.RowIndex]["Project_Title"]);
            DropDownList ddlProblem = row.FindControl("ddlSelectProblem") as DropDownList;
            ddlSelectProblem.SelectedItem.Text = Convert.ToString((row.Parent.Parent as GridView).DataKeys[row.RowIndex]["Problem"]);
            txtProjectStartDate.Text = Convert.ToString((row.Parent.Parent as GridView).DataKeys[row.RowIndex]["Project_Start_Date"]);
            TextBox1.Text = Convert.ToString((row.Parent.Parent as GridView).DataKeys[row.RowIndex]["Project_Target_Date"]);
        }
C# asp.net GridView FindControl

评论

0赞 Chetan 11/1/2019
您在此代码中面临什么问题?
0赞 Nits Patel 11/1/2019
它显示其他信息:对象引用未设置为对象的实例。
0赞 Nits Patel 11/1/2019
我得到了我的输出,因为我需要 Thanx 的响应

答: 暂无答案