I have a Rad gridview that databinds and popluates date according to a seacrh. There is a linkbutton that i want to be able to change on column from saying false to true or vice-versa. Please help.
void btn1_Click(object sender, EventArgs e)
{
var btnChange = (LinkButton)sender;
var change = from s in db.Users
where s.AccountID == ??
select s;
}
I need to be able to get the correct row in which I clicked the button to change its particluar column value
void btn1_Click(object sender, EventArgs e)
{
var btnChange = (LinkButton)sender;
var change = from s in db.Users
where s.AccountID == ??
select s;
}
I need to be able to get the correct row in which I clicked the button to change its particluar column value
10 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Feb 2014, 12:51 PM
Hello,
1.
2.
Thanks,
Jayesh Goyani
<MasterTableView DataKeyNames="ID"> <Columns> <telerik:GridTemplateColumn> <ItemTemplate> <asp:Button ID="btn1" runat="server" CommandArgument='' <%# Eval("ID") %> /> </ItemTemplate> </telerik:GridTemplateColumn> <%-- <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"> </telerik:GridBoundColumn>--%> </Columns> </MasterTableView>1.
void btn1_Click(object sender, EventArgs e) { var btnChange = (LinkButton)sender; var change = from s in db.Users where s.AccountID == btnChange.CommandArgument select s; }2.
void btn1_Click(object sender, EventArgs e) { var btnChange = (LinkButton)sender; var dataitem = btnChange.NamingContainer as GridDataItem; var change = from s in db.Users where s.AccountID == dataitem.GetDataKeyValue("ID") select s; }Thanks,
Jayesh Goyani
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Feb 2014, 12:52 PM
Hello,
Please use "AccountID" in-place of "ID" in above code snippet.
Thanks,
Jayesh Goyani
Please use "AccountID" in-place of "ID" in above code snippet.
Thanks,
Jayesh Goyani
0
Princy
Top achievements
Rank 2
answered on 18 Feb 2014, 12:55 PM
Hi Grant,
You can use the DataKeyValue and access the specific row. Please have a look at the following code snippet:
ASPX:
C#:
Thanks,
Princy
You can use the DataKeyValue and access the specific row. Please have a look at the following code snippet:
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"> <MasterTableView DataKeyNames="OrderID"> <Columns> . . . <telerik:GridTemplateColumn> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Check</asp:LinkButton> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void LinkButton1_Click(object sender, EventArgs e){ LinkButton lnkbtn = (LinkButton)sender; GridDataItem item = (GridDataItem)lnkbtn.NamingContainer; String id = item.GetDataKeyValue("OrderID").ToString();// Get corresponding row id }Thanks,
Princy
0
Grant
Top achievements
Rank 1
answered on 18 Feb 2014, 01:19 PM
Thank you for all your very quick replies, atleast i know where to come in future.
this is my source code :
<MasterTableView DataKeyNames ="OrderID" TableLayout ="Fixed">
<Columns>
...
<telerik:GridButtonColumn ButtonType="LinkButton" FilterControlAltText="Filter column column" Text="Change" UniqueName="btnChange" CommandName="Delete">
<HeaderStyle Width="50px" />
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
this is my source code :
<MasterTableView DataKeyNames ="OrderID" TableLayout ="Fixed">
<Columns>
...
<telerik:GridButtonColumn ButtonType="LinkButton" FilterControlAltText="Filter column column" Text="Change" UniqueName="btnChange" CommandName="Delete">
<HeaderStyle Width="50px" />
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
0
Grant
Top achievements
Rank 1
answered on 18 Feb 2014, 01:22 PM
Hi Princy
Your code considerably different to mine, would you be able to assist me with code I provided?
Grant.
Your code considerably different to mine, would you be able to assist me with code I provided?
Grant.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Feb 2014, 04:37 PM
Hello,
Method 1
Method 2
Let me know if any concern.
Thanks,
Jayesh Goyani
Method 1
void btn1_Click(object sender, EventArgs e) { var btnChange = (LinkButton)sender; var change = from s in db.Users where s.AccountID == btnChange.CommandArgument select s; }<telerik:GridButtonColumn ButtonType="LinkButton" FilterControlAltText="Filter column column" Text="Change" UniqueName="btnChange" CommandName="Delete" CommandArgument='<%# Eval("AccountID") %>' ><HeaderStyle Width="50px" /></telerik:GridButtonColumn>Method 2
void btn1_Click(object sender, EventArgs e) { var btnChange = (LinkButton)sender; var dataitem = btnChange.NamingContainer as GridDataItem; var change = from s in db.Users where s.AccountID == dataitem.GetDataKeyValue("ID") select s; }<MasterTableView DataKeyNames="AccountID">....................<telerik:GridButtonColumn ButtonType="LinkButton" FilterControlAltText="Filter column column" Text="Change" UniqueName="btnChange" CommandName="Delete"><HeaderStyle Width="50px" /></telerik:GridButtonColumn>Let me know if any concern.
Thanks,
Jayesh Goyani
0
Grant
Top achievements
Rank 1
answered on 19 Feb 2014, 08:03 AM
Hi Jayesh Goyani
There was an exception :
"There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource."
its because i added DataKeyNames="AccountID"
There was an exception :
"There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource."
its because i added DataKeyNames="AccountID"
0
Grant
Top achievements
Rank 1
answered on 19 Feb 2014, 08:07 AM
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Feb 2014, 08:09 AM
Hello,
Please add below code snippet.
Note : Please make sure AccountID field is exists in your assigned datasource.
Thanks,
Jayesh Goyani
Please add below code snippet.
<MasterTableView DataKeyNames="AccountID">Note : Please make sure AccountID field is exists in your assigned datasource.
Thanks,
Jayesh Goyani
0
Grant
Top achievements
Rank 1
answered on 19 Feb 2014, 09:40 AM
Thank you so much Jayesh.
Problem solved.
Now I just have to firgure out this problem with th databind.
Regards
Grant
Problem solved.
Now I just have to firgure out this problem with th databind.
Regards
Grant