我如何将数据绑定到作为EditItemTemplate的gridview中的下拉列表 [英] How can i bind data to a dropdown in the gridview which is an EditItemTemplate

查看:138
本文介绍了我如何将数据绑定到作为EditItemTemplate的gridview中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我声明了我的模板,如下所示

I declared my template as follows

<EditItemTemplate>
    <asp:DropDownList ID="ddlYear" runat="server" 
                      DataSource=''<%#GetYears() %>'' 
                      DataTextField="year" 
                      DataValueField="year" />
</EditItemTemplate>



我需要从使用GetYears()的函数中绑定数据,但我不知道该如何运行,任何人都可以帮助我.

当我单击"GridView的编辑"时,我需要在下拉菜单中加载年份"的数据,这是正确的方法还是有最佳方法?



I need to bind the data from the function i used GetYears() i don''t know how to function it can any one help me.

I need the data for example Years to be loaded in dropdown when i click on Edit of gridview is it the correct way or is there any best way to do this.

推荐答案

您好,请参见 [链接2 [
Hi see this[^]

Link 2[^]


您所做的是正确的.

但是从优化的角度来看,我认为每当发生行绑定时,都会执行您的函数"GetYears".

我能想到的最好的办法是,创建一个属性(在viewstate中存储值),该属性在页面加载时使用函数"GetYears()"进行初始化,然后使用它填充下拉列表.这将每次保存您的函数调用.另外,仅在您的媒体资源为空时,才在页面加载时进行验证以调用GetYears.

希望能有所帮助. :)
What you have done is correct.

But from the optimization point of view I think that every time when the row binding will occur, your function "GetYears" will be executed.

What the best I can think of is, make a property (store value in viewstate) which gets initialized at page load with function "GetYears()" and then use it to fill the drop down. This will save your function call each time. Plus do a validation at page load to call GetYears only when your property is empty.

Hope that helps. :)


这篇关于我如何将数据绑定到作为EditItemTemplate的gridview中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆