Hi there i have a radgrid on which i have to find a value and if the item is found then generate message
嗨,我有一个radgrid,我必须找到一个值,如果找到该项,然后生成消息
below is my code
下面是我的代码
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
If IsAlreadyExist() Then
ram.Alert("")
Else
If IsAlreadyAdded() Then
ram.Alert("")
Else
employees()
End If
End If
End Sub
and here is the IsAlreadyAdded mehtod in which iam trying to find a specific value in grid if it exists it will return false
这里是IsAlreadyAdded mehtod,iam试图在网格中找到一个特定的值,如果它存在,它将返回false
Private Function IsAlreadyAdded() As Boolean
'If rgListnk.MasterTableView.Items.Count > 0 Then
Dim itm As GridDataItem = rgList.MasterTableView.FindItemByKeyValue("DEFAULT", "Y")
If IsNothing(itm) Then
Return False
Else
Return True
End If
End Function
Thanks...
谢谢...
1 个解决方案
#1
2
You need to loop through each row of the Grid in order to find a value of a cell.
您需要遍历网格的每一行以查找单元格的值。
Make sure DataKeyNames is specified if you want to find item by FindItemByKeyValue.
如果要通过FindItemByKeyValue查找项目,请确保指定了DataKeyNames。
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadGrid ID="RadGrid1" runat="server"
OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView DataKeyNames="Id">
</MasterTableView>
</telerik:RadGrid>
<asp:Button runat="server" ID="Button1"
OnClick="Button1_Click" Text="Submit" />
public partial class Default : System.Web.UI.Page
{
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadGrid1_NeedDataSource(object sender,
GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = new List<User>
{
new User {Id = 1, FirstName = "Jon", LastName = "Doe"},
new User {Id = 2, FirstName = "Marry", LastName = "Doe"},
new User {Id = 3, FirstName = "Eric", LastName = "Newton"},
};
}
protected void Button1_Click(object sender, EventArgs e)
{
var firstItem = RadGrid1.MasterTableView.FindItemByKeyValue("Id", 1);
if (firstItem != null)
{
var firstName = firstItem["FirstName"].Text;
var lastName = firstItem["lastName"].Text;
}
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridDataItem)
{
var dataItem = item as GridDataItem;
var firstName = dataItem["FirstName"].Text;
var lastName = dataItem["lastName"].Text;
}
}
}
}
#1
2
You need to loop through each row of the Grid in order to find a value of a cell.
您需要遍历网格的每一行以查找单元格的值。
Make sure DataKeyNames is specified if you want to find item by FindItemByKeyValue.
如果要通过FindItemByKeyValue查找项目,请确保指定了DataKeyNames。
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadGrid ID="RadGrid1" runat="server"
OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView DataKeyNames="Id">
</MasterTableView>
</telerik:RadGrid>
<asp:Button runat="server" ID="Button1"
OnClick="Button1_Click" Text="Submit" />
public partial class Default : System.Web.UI.Page
{
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadGrid1_NeedDataSource(object sender,
GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = new List<User>
{
new User {Id = 1, FirstName = "Jon", LastName = "Doe"},
new User {Id = 2, FirstName = "Marry", LastName = "Doe"},
new User {Id = 3, FirstName = "Eric", LastName = "Newton"},
};
}
protected void Button1_Click(object sender, EventArgs e)
{
var firstItem = RadGrid1.MasterTableView.FindItemByKeyValue("Id", 1);
if (firstItem != null)
{
var firstName = firstItem["FirstName"].Text;
var lastName = firstItem["lastName"].Text;
}
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridDataItem)
{
var dataItem = item as GridDataItem;
var firstName = dataItem["FirstName"].Text;
var lastName = dataItem["lastName"].Text;
}
}
}
}