是否有可能在页面加载时获取listview中的控件值? [英] Is it possible to get the value of a control inside listview on page load?

查看:47
本文介绍了是否有可能在页面加载时获取listview中的控件值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var test =((HiddenField)lstDetails.FindControl(HiddenField1))。值;



但我收到错误对象引用未设置为实例一个对象。





提前致谢。



< br $>


var test = ((HiddenField)lstDetails.FindControl("HiddenField1")).Value;

But i get error "Object reference not set to an instance of an object."


Thanks in advance.



<asp:ListView ID="lstDetails" runat="server" ItemPlaceholderID="itemPlaceHolder"

                                     OnSelectedIndexChanging="lstDetails_SelectedIndexChanging"

                                     OnSelectedIndexChanged="lstDetails_SelectedIndexChanged" >

                                    <LayoutTemplate>
                                        <table style="width:1074px;">
                                            <thead>
                                                <tr class="tableHead">
                                                    <th style="text-align: center; width: 35px;">Sl</th>
                                                    <th style="text-align: center; width: 850px;">Leave Approval</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
                                            </tbody>
                                        </table>
                                    </LayoutTemplate>
                                    <ItemTemplate>
                                        <table class="tablemain" style="position:relative; left:66px;">
                                            <tr>
                                                <td>

                                                </td>
                                            </tr>
                                            <tr >
                                                <td class="tablecontentTitleSmall">Leave #</td>
                                                <td class="tablecontent">
                                                    <asp:HiddenField ID="hfSearchID" Value='<%#Eval("EssDocAppNo") %>' runat="server" />
                                                    <asp:TextBox ID="txtID" runat="server" CssClass="formTextBox" Text='<%#Eval("leave#") %>' Enabled="false"></asp:TextBox>
                                                </td>
                                                <td class="tablecontentTitleSmall">Employee Name</td>
                                                <td colspan="5" class="tablecontent">
                                                    <asp:TextBox ID="txtEmployeeName" runat="server" CssClass="formTextBox" Text='<%#Eval("FullName") %>' Enabled="false" Width="668px"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="tablecontentTitleSmall">Date
                                                </td>
                                                <td class="tablecontent">
                                                    <asp:TextBox ID="txtApplyDate" runat="server" CssClass="formTextBox" Text='<%#Eval("ladate") %>' Enabled="false"></asp:TextBox>
                                                </td>
                                                <td class="tablecontentTitleSmall">From
                                                </td>
                                                <td class="tablecontent">
                                                    <asp:TextBox ID="txtFromDate" runat="server" CssClass="formTextBox" Text='<%#Eval("leavestart") %>' Enabled="false"></asp:TextBox>
                                                </td>
                                                <td class="tablecontentTitleSmall">To
                                                </td>
                                                <td class="tablecontent">
                                                    <asp:TextBox ID="txttoDate" runat="server" CssClass="formTextBox" Text='<%#Eval("leaveend") %>' Enabled="false"></asp:TextBox>
                                                </td>
                                                <td class="tablecontentTitleSmall">No of Days
                                                </td>
                                                <td class="tablecontent"  style="width:63px;">
                                                    <asp:TextBox ID="txtNoofDays" runat="server" CssClass="formTextBox" Text='<%#Eval("noofdays") %>' Enabled="false"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="tablecontentTitleSmall"></td>
                                                <td class="tablecontent">
                                                     <span>
                                                <asp:ImageButton ID="imgApprove" Width="30" Height="30" ToolTip="Approve" OnClick="imgApprove_Click" CommandName="Select"  CommandArgument="approve" ImageUrl="~/Styles/images/Approve.png" PostBackUrl='#' runat="server" /></span>

                                            <span>
                                                <asp:ImageButton ID="imgDenied" Width="30" Height="30" ToolTip="Deny" CommandName="Select" CommandArgument="deny" ImageUrl="~/Styles/images/Denied.png" PostBackUrl='#' runat="server" /></span>
                                                </td>
                                                <td class="tablecontentTitleSmall">Reason
                                                </td>
                                                <td class="tablecontent">
                                                    <asp:DropDownList ID="ddlReason" runat="server" Width="130px" CssClass="formTextBox">
                                                        <asp:ListItem>Eligible</asp:ListItem>
                                                        <asp:ListItem>Not Eligible</asp:ListItem>
                                                    </asp:DropDownList>
                                                </td>
                                                <td colspan="4" class="tablecontent">
                                                    <asp:TextBox ID="txtComment" runat="server" CssClass="formTextBox" Width="520px" TextMode="MultiLine"></asp:TextBox>
                                                </td>

                                            </tr>
                                        </table>
                                        <div style="height: 1px; width: 1007px; background-color: black; position: relative; left: 67px">
                                        </div>
                                    </ItemTemplate>
                                </asp:ListView>















/////////////////////////////////////////////////////////////////////////





select d.EssDocAppNo,(e.EmpFName+’ ’+ e.EmpMName+’ ’+e.EmpLName)as FullName,(l.essdoccode+’ ’+CONVERT(varchar(10), l.EssLaNo))as leave# ,l.ladate,l.leavestart,l.leaveend,l.noofdays from MstEmployee e,EssTrnLeaveApplication l,Ess TrnDocumentApproval d,UtlWorkFlow w where l.EmpCode=4092 and e.EmpCode=4092and e.EmpCode=4092 and d.ApprovalStatus=’P’ and w.Authority1=2068;








/////////////////////////////////////////////////////////////////////////


select d.EssDocAppNo,(e.EmpFName+' '+ e.EmpMName+' '+e.EmpLName)as FullName,(l.essdoccode+' '+CONVERT(varchar(10), l.EssLaNo))as leave# ,l.ladate,l.leavestart,l.leaveend,l.noofdays from MstEmployee e,EssTrnLeaveApplication l,EssTrnDocumentApproval d,UtlWorkFlow w where l.EmpCode=4092 and e.EmpCode=4092and e.EmpCode=4092 and d.ApprovalStatus='P' and w.Authority1=2068;

推荐答案

you have hidden field called hfSearchID but you searching for HiddenField1. correct that first.

after you binding data try below

you have hidden field called hfSearchID but you searching for HiddenField1. correct that first.
after you binding data try below
var test = ((HiddenField)lstDetails.Items[0].FindControl("hfSearchID")).Value;





note that you have hidden fields for each item, above will give the first list item hidden control



note that you have hidden fields for each item, above will give the first list item hidden control


这篇关于是否有可能在页面加载时获取listview中的控件值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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