需要帮助在Asp.Net(C#)中自定义GridView控件 [英] Need help with customizing GridView control in Asp.Net (C#)

查看:70
本文介绍了需要帮助在Asp.Net(C#)中自定义GridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用模板构建了一个可自定义的GridView。我提供了< ItemTemplate>和< EditItemtemplate>字段有TextBoxes,DropDownList和RadioButtonList控件。

I build a customizable GridView with Templates and all that. I provided for <ItemTemplate> and <EditItemtemplate>fields having TextBoxes, DropDownList and RadioButtonList controls.

现在我想使用方法(函数)来呈现数据(例如,在db表中我将性别设置为True( forMale)和False(对于Female)。现在我希望GridView中的Label控件调用一个方法,将整个GridView Row传递给它,然后该方法应返回一个字符串
" Male"如果gender == True in db和这个字符串应该是调用方法的标签的文本)....

Now i want to use Methods(functions) to present data(e.g, in the db table i have gender as True(forMale) and False(for Female).Now i want the Label control in GridView to call a method,pass entire GridView Row to it,then the method should return a string "Male" if gender==True in db and this string should be the text of the very label that called the method)....



更多,当我编辑任何行时,我'已经放置说,RadioButtonList用于性别,但默认情况下没有选择单选按钮。如果用户忘记单击单选按钮,则会导致错误。我希望它检查性别的先前值并保留其中一个收音机
根据以前的值选择按钮.....


FurtherMore,when i edit any Row, i've placed say, RadioButtonList for gender,but it has no radiobutton selected ,by default.This leads to errors if user forgets to click a radio button. I want it to check the previous values for Gender and keep one of the radio Buttons selected depending on the previous values.....

此外,当我按下编辑时按钮,我不能在GridView1_rowupdating方法中使用FindControl方法,以找到< EditItemTemplate>的控件。


另外,我在GridView中放了两个按钮。我希望这两个按钮仅对那些approval_stage!=零的行启用。

请帮助,我需要在几天内完成我的项目。我没有时间:(

部分代码在这里:



MyFile.aspx: -

Also, when i press the Edit button, i cant use FindControl method in GridView1_rowupdating method, to find the controls of <EditItemTemplate>.
Also, i have put two buttons in the GridView. I want these two buttons to be enabled for only those rows where approval_stage != zero.
Please Help, i need to complete my project in just a few days. I don't have time :(
Some of code is here:

MyFile.aspx:-

 


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="True" PageSize="3" 
DataKeyNames
="request_no" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" > <Columns> <asp:ButtonField DataTextField="request_no" HeaderText="request_no" CommandName="request_no" /> <asp:TemplateField HeaderText="date"> <EditItemTemplate> <asp:Calendar ID="Calendar1" runat="server" ></asp:Calendar> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label5" runat="server" Text='<%# Bind("date") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="approval_stage"> <EditItemTemplate> <asp:DropDownList ID="DropDownListApproval" runat="server"> <asp:ListItem Value ="0" >0</asp:ListItem> <asp:ListItem Value ="1" >1</asp:ListItem> <asp:ListItem Value ="2" >2</asp:ListItem> <asp:ListItem Value ="3" >3</asp:ListItem> <asp:ListItem Value ="4" >4</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# DisplayApproval(Eval("approval_stage")) %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="name" HeaderText="name" /> <asp:TemplateField HeaderText="gender"> <EditItemTemplate> <asp:RadioButtonList ID="RadioButtonListGender" runat="server"> <asp:ListItem Value="False">Male</asp:ListItem> <asp:ListItemValue="True">Female</asp:Li… </asp:RadioButtonList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# DisplayGender(Eval("gender")) %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:ButtonField ButtonType="Button" CommandName="approve" Text="approve" /> <asp:ButtonField ButtonType="Button" CommandName="reject" Text="reject" /> <asp:CommandField ButtonType="Button" HeaderText="Edit" ShowEditButton="True" ShowHeader="True" /> </Columns> </asp:GridView>

推荐答案

这个问题与ASP.NET论坛有关,但无论如何我会尝试给出一些输入。您需要具有与数据库中不完全相同的显示值。没有什么可担心的,因为这样的改变可以在grifView_RowDataBound()事件中完成,并且它们是直接的
。请参考以下链接,它可以帮助您实现您想要的目标。

This question pertains to ASP.NET forum but anyway I would try to give some inputs. You need to have display values which are not exactly same as in database. Nothing to worry much as such changes can be done in grifView_RowDataBound() event and they are straightforward. Please refer to following link which can help you to achieve what you want to.

http://msdn.microsoft.com/en-us/library/ms972833.aspx

希望这会有所帮助。

 

 

 


这篇关于需要帮助在Asp.Net(C#)中自定义GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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