GridView的RowDataBound没有运行代码 [英] GridView RowDataBound not running code

查看:130
本文介绍了GridView的RowDataBound没有运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql中有Ref table和patientDetails。例如在参考资料中,我有性别列(包括女性,男性等),在患者详细信息中,性别列是24,我将数据绑定到患者详细信息,并且在Gridview的Gender列中有24个,但它应该是女性。 (外键和导航属性不起作用,因为我在Ref表中有很多不同的行,例如种族,宗教等)。我被告知RowDataBound将工作,所以我现在有这种方法,但它不会通过If语句行。



更多详情:



我的数据源绑定到具有Gender列的PatientDetails表(具有数值 - 从ref表中获取)。我的意思是我有Ref table(就像查找所有内容 - 带有列ID,名称,描述)名字上我有性别,族群,宗教)在描述列中我有例如性别的值:男性,女性等性别列中的性别列将返回值的相应参考ID - 对于女性,它将在性别列中存储24位患者),所以我的Gridview正确绑定并获取存储在PatientDetails表中的数据,但性别无效24,25显示所以我被告知RowDataBound可以在Ref表中引入正确的相应值

 受保护的子gvPatientDetails_RowDataBound(sender As Object,e As GridViewRowEventArgs)
如果e.Row.RowType = DataControlRowType.DataRow Then
Dim lblGender As Label = e.Row.FindControl(lblGender)
End If
End Sub


< asp:GridView ID =gvPatientDetailsrunat =serverAutoGenerateColumns =falseOnRowDataBound =gvPatientDetails _RowDataBound>

<列>
< asp:TemplateField HeaderText =Gender>
< ItemTemplate>
< asp:Label ID =lblGenderrunat =serverText ='<%#Eval(lblGender)%>'>< / asp:Label>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>


解决方案

好的,我知道了。



对于所有可能会遇到这种情况的初学者来说,上面的代码是按照它应该的方式工作的,当我第一次调试它时碰到IF语句,然后不进去(因为第一个其中一个是Header(我知道这个),继续它应该给你标签的实际值,然后它应该很简单,只需getDataFromRef(一种从Ref-id = lblGender获取数据的方法),然后

  lblGender.Text =(来自method  -  getDataFromRef的值)。

基本上我没有意识到调试器会以Header开头,那么当您点击继续时,将会经过gridview行!



<所有最好的一切,快乐的编码!:)

I have Ref table and patientDetails in sql. for example in Ref I have Gender column with values (Female, Male etc), In patientDetails the Gender column is 24 and I am binding the data to patientDetails and I have 24 in the Gender column in the Gridview but it should be Female. ( Foreign key and navigation properties would not work because I have so many different rows in Ref table like ethnicity,religion etc). I was told RowDataBound will work so I have this method now but its not going past the If statement line..

More Details:

my Data Source is binding to PatientDetails table which has Gender column ( with number values - which is getting it from ref table). I mean I have Ref table ( Like a lookup for everything - with columns ID, name, Description) In name I have gender, Ethnic group, religion) In Description Column I have the values for instance for gender: male, female etc however in the Gender column in Patient is returning the corresponding Ref ID of the value - for female it will store 24 in Gender column in Patient) so my Gridview is bounding correctly and getting whats stored in PatientDetails table however having 24, 25 in Gender is not helpful to show so I was told RowDataBound Can bring the correct correponding value in Ref table

 Protected Sub gvPatientDetails_RowDataBound(sender As Object, e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim lblGender As Label = e.Row.FindControl("lblGender)
    End If
End Sub


 <asp:GridView ID="gvPatientDetails" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvPatientDetails_RowDataBound">

<Columns>
            <asp:TemplateField HeaderText="Gender">
                <ItemTemplate>
            <asp:Label ID="lblGender" runat="server" Text='<% #Eval("lblGender") %>'></asp:Label>
                </ItemTemplate>
  </asp:TemplateField>
        </Columns>
    </asp:GridView>

解决方案

OK, I got it working.

For all the beginners who might struggle with this, the above code is working as it should, when I debug it first time it just hit the IF statement then doesnt go inside ( because the first one is Header (I know duh!!) hit continue and it should give you the actual value of label then after that it should be simple. Just getDataFromRef ( a method to get data from Ref - id = lblGender ) then

lblGender.Text = ( The value from method - getDataFromRef ).

Basically I wasn't aware the debugger will start with the Header then when you hit continue will go through the gridview rows!

All the best all, happy coding!:)

这篇关于GridView的RowDataBound没有运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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