网格视图列隐藏但数据使用 [英] Grid view column hide But Data use
本文介绍了网格视图列隐藏但数据使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望隐藏网格视图列,但使用这些值.如果可能,请帮助我.
I Want grid view column hide but these value use.If possible then pls help me.
<asp:GridView ID="grdManualAttendance" runat="server" DataKeyNames="AttendanceID" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
Font-Size="Small" Width="100%" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField ItemStyle-Width="20px">
<HeaderTemplate>
Delete
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AttendanceID" HeaderText="AttendanceID" visible="false" ItemStyle-Width="20px" />
<asp:BoundField DataField="Date" DataFormatString="{0:dd/mm/yyyy}" HeaderText="Date"
ItemStyle-Width="20px" />
<asp:BoundField DataField="Time" DataFormatString="{0:hh:mm:ss}" HeaderText="Time" ItemStyle-Width="20px" />
<asp:BoundField DataField="GraceTime" HeaderText="GraceTime"
ItemStyle-Width="20px" />
<asp:BoundField DataField="IsActive" HeaderText="IsActive"
ItemStyle-Width="20px" />
<asp:BoundField DataField="Remarks" HeaderText="Remarks"
ItemStyle-Width="20px" />
</Gridview>
AttendanceID colunm隐藏但该ID需要Delete.但是我找不到此ID.请提供适当的解决方案.
AttendanceID colunm Hide but This id need for Delete.But i cant find this ID. Pls give appropriate solution.
推荐答案
可能会帮助您
然后将field设为TemplateField
,并将ID绑定到HiddenField
中,并在删除时在该特定列上找到Control HiddenField.
谢谢
May it will help you
Make then field as aTemplateField
and bind the ID in aHiddenField
and while deleting find the Control HiddenField on that particular column.
Thanks
使用gridview的DataKeyNames属性.
use DataKeyNames property of gridview.
<asp:gridview id="gridview1" runat="server" datakeynames="Id">
<columns>
</columns>
</asp:gridview>
并在代码隐藏中使用它
and use it in codebehind
id = Convert.ToDateTime(gridview1.DataKeys[row.RowIndex].Values[0]);
尝试一下,使用templateFiled而不是boundfield并在其中保留一个hidednfield.
Try this, Use templateFiled instead of boundfield and keep a hidednfield inside it.
<asp:templatefield visible="false">
<asp:hiddenfield id="hdnAttendanceID" runat="server" value='<%=Eval("AttendanceID"); %>'>
</asp:hiddenfield>
</asp:templatefield>
然后在Row_Command事件的代码后面
And later in codebehind Row_Command event
GridViewRow gvr= (GridViewRow) e.CommandSource
HiddenField hdnAttendanceID= (HiddenField)gvr.FindControl("hdnAttendanceID");
string AttendanceID= hdnAttendanceID.Value;
这篇关于网格视图列隐藏但数据使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文