i am getting nothing , i am trying to retrieve checkbox value and email address from gridview via code, I am succeeded in getting Checkbox value successfully but cannt get email address, even grid view has it, but i cant get, just blank, here is the code:
.cs :
protected void GridViewAdminViewEmplys_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
//Response.Write("Updated");
GridView gvr = GridViewAdminViewEmplys;
int index = Convert.ToInt32(e.CommandArgument);
int pk = Convert.ToInt32(GridViewAdminViewEmplys.DataKeys[index].Value);
Response.Write(pk);
bool isChecked = (gvr.Rows[index].Cells[8].Controls[0] as CheckBox).Checked;
//CheckBox chk = (CheckBox)gvr.Rows[index].FindControl("chkBoxStatus");
// Response.Write(isChecked);
if (isChecked == true)
{
String email = gvr.Rows[index].Cells[3].Text;
Response.Write(email);
Response.Write("TRUE CONDITION");
}
else
{
Response.Write("False condition");
}
Hunain Hafee...
Member
238 Points
639 Posts
cannot get string value from gridview via code
Nov 12, 2012 08:50 PM|LINK
i am getting nothing , i am trying to retrieve checkbox value and email address from gridview via code, I am succeeded in getting Checkbox value successfully but cannt get email address, even grid view has it, but i cant get, just blank, here is the code:
.cs :
protected void GridViewAdminViewEmplys_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Update") { //Response.Write("Updated"); GridView gvr = GridViewAdminViewEmplys; int index = Convert.ToInt32(e.CommandArgument); int pk = Convert.ToInt32(GridViewAdminViewEmplys.DataKeys[index].Value); Response.Write(pk); bool isChecked = (gvr.Rows[index].Cells[8].Controls[0] as CheckBox).Checked; //CheckBox chk = (CheckBox)gvr.Rows[index].FindControl("chkBoxStatus"); // Response.Write(isChecked); if (isChecked == true) { String email = gvr.Rows[index].Cells[3].Text; Response.Write(email); Response.Write("TRUE CONDITION"); } else { Response.Write("False condition"); }.aspx:
<asp:GridView ID="GridViewAdminViewEmplys" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="userid" DataSourceID="SqlDataSource1" AllowSorting="True" OnRowCommand="GridViewAdminViewEmplys_RowCommand" > <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:HyperLinkField DataNavigateUrlFields="userid" DataNavigateUrlFormatString="~/adminViewEmplyrFurther.aspx?userid={0}" DataTextField="userid" DataTextFormatString="{0}" HeaderText="Userid" InsertVisible="False" NavigateUrl="~/adminViewEmplyrFurther.aspx" SortExpression="userid" /> <asp:BoundField DataField="fullname" HeaderText="fullname" SortExpression="fullname" /> <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" /> <asp:BoundField DataField="question" HeaderText="question" SortExpression="question" /> <asp:BoundField DataField="answers" HeaderText="answers" SortExpression="answers" /> <asp:BoundField DataField="doc" HeaderText="doc" SortExpression="doc" /> <asp:BoundField DataField="roleid" HeaderText="roleid" SortExpression="roleid" /> <asp:CheckBoxField DataField="active" HeaderText="Status" SortExpression="active" ReadOnly="false" /> <%--<asp:TemplateField HeaderText="Status" > <ItemTemplate> <asp:CheckBox ID="chkBoxStatus" runat="server" Checked='<%# Convert.ToString(Eval("active")) %>' /> </ItemTemplate> </asp:TemplateField>--%> </Columns> </asp:GridView>Madhu1234
Participant
1380 Points
287 Posts
Re: cannot get string value from gridview via code
Nov 12, 2012 10:27 PM|LINK
May be ur checkbox value is false..just check..
Hunain Hafee...
Member
238 Points
639 Posts
Re: cannot get string value from gridview via code
Nov 13, 2012 11:35 AM|LINK
i checked that , but still not working
Madhu1234
Participant
1380 Points
287 Posts
Re: cannot get string value from gridview
Nov 13, 2012 06:21 PM|LINK
String email = gvr.Rows[index].Cells[3].Text;
Replace the above line like this...
String email = gvr.Cells[3].Text;
You need not use Rows[index] as you already have gridview row...
Also try to get gridviewrow like this...
GridViewRow gvr =GridViewAdminViewEmplys.Rows[indRow];
Hunain Hafee...
Member
238 Points
639 Posts
Re: cannot get string value from gridview
Nov 13, 2012 06:30 PM|LINK
sorry but it isn't working , wthout using Rows property , it won't call Cells, i tried !
please help !
paindaasp
Star
12050 Points
2034 Posts
Re: cannot get string value from gridview
Nov 13, 2012 06:39 PM|LINK
I believe, since, you're in edit mode the text will be in a TextBox. Try:
Hunain Hafee...
Member
238 Points
639 Posts
Re: cannot get string value from gridview
Nov 13, 2012 07:09 PM|LINK
wowww ! it worked man ! u r genius !
thanks alot !
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: cannot get string value from gridview via code
Nov 16, 2012 08:25 AM|LINK
Add LinkButton to ItemTemplate and bind CommandArgument property to row index:
<asp:TemplateField HeaderText="Vendor Name"> <ItemTemplate> <asp:LinkButton ID="lnkvendorname" runat="server" CommandArgument='<%#Eval("userid")%>' CommandName="Update" Text="Get"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>view the page and click the link button, please give a try
Feedback to us
Develop and promote your apps in Windows Store
sarathi125
Star
13599 Points
2691 Posts
Re: cannot get string value from gridview via code
Nov 16, 2012 09:04 AM|LINK
Hi,
Check that are you getting the correct index?
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets