查找网格视图控件控制

查找网格视图控件控制

本文介绍了查找网格视图控件控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多的问题和放大器;这个答案,但他们不为我的作品

试图通过函数后面code填充此下拉列表:

该下拉列表是图片的名称,当用户选择一个,点击在网格视图我需要插入一个后缀为映像名称更新链接按钮(的路径)
因此,如果用户从列表中选择一个图像名称更新按钮,它实际上将更新文件名+插入开头的路径,所以这将是

for the name gary.

 <asp:TemplateField>
                <EditItemTemplate>
                        <asp:DropDownList ID="ddlImages" runat="server">
                        <Items>
                            <asp:ListItem Text="Choose" Value="" />
                        </Items>
                    </asp:DropDownList>
                </EditItemTemplate>
                ...
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlImages = (e.Row.FindControl("ddlImages") as DropDownList);
            ShowImages(ddlImages);

        }
}

"ddlImages" is null, how can I find him?


Managed to find the drop down list like that:

if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                DropDownList ddlImages = (DropDownList)e.Row.FindControl("ddlImages");
                ddlImages.DataSource = GetImages();
                ddlImages.DataBind();
            }
        }

Now i am facing another problem, in the aspx i have an "UpdateCommand" which take parameters and try to update the database. The problem- it need to take the dropDownList chosen value but instead it take: "" how can i change it to take the value that the user choose in the dropDownList

    UpdateCommand="UPDATE [investigator] SET [name] = @name, [area] = @area, [country] = @country,     [picture] = @picture, [review] = @review WHERE [Id] = @Id">

 <UpdateParameters>
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="area" Type="String" />
            <asp:Parameter Name="country" Type="String" />
            <asp:Parameter Name="picture" Type="String" />
            <asp:Parameter Name="review" Type="String" />
            <asp:Parameter Name="Id" Type="Int32" />
        </UpdateParameters>

Meaning- I have to change

<asp:Parameter Name="picture" Type="String" />

to drop down list selected value. How can I achieve that?

解决方案

Regarding your question about the update Parameter, you should use the ControlParameter instead of general Parameter. Try replacing the Parameter Definition for the Dropdown list with followingcode.

<asp:ControlParameter Name="picture" ControlID="ddlImages"
    PropertyName="SelectedValue" Type="String" />

UPDATEWhat you can do as alternate is,

Change the parameter back to

<asp:Parameter Name="picture" Type="String" />

Add RowUpdating event handler to the gridviewIn the RowUpdating command set the data source parameter based on the selected value as below

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

GridViewRow row = GridView1.Rows[e.RowIndex];
DropDownList ddlImages=  row.FindControl("ddlImages") as DropDownList;
SqlDataSource1.UpdateParameters["picture"].DefaultValue = ddlImages.SelectedValue;
}

这篇关于查找网格视图控件控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:53