its like scrapbook in orkut however the user who has sent msg can delete only his/her scrap so there he/she find delete button but for other scraps not..
i am using gridview with sqldatasource control
Thank you!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit ChoudharyPosted Mar 11, 2010, 11:59 PM
you have to change your function little bit.
Like this:
public bool isOwner(int scrapId)
{
// assign a default value to flag
bool flag=false;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
Label lbl = (Label)GridView1.Rows[i].FindControl("lblfromId");
if (lbl.Text == pid.ToString())
{
flag=true;
}
else
{
flag=false;
}
}
return flag;
}
Explaination: The error you are doing is, you are returning the valued inside the for loop that itself having a condition so if loop does't get start cause condition not me then nothing will return to the function. so giving error.
Please Don't forget to mark as answer.
Sandeep SharmaPosted Aug 5, 2014, 9:41 AM
this is working for me try something like this.
Dipa AhujaPosted Mar 12, 2010, 10:59 AM
void showdlt()
{
bool flag = false;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
Label lbl = (Label)GridView1.Rows[i].FindControl("lblfromId");
Button btn = (Button)GridView1.Rows[i].FindControl("btndelete");
if (lbl.Text == p.profile_Id.ToString())
{
btn.Visible = true;
flag = true;
}
else
{
btn.Visible = false;
flag = false;
}
}
}
and call this method in page_load() event...
bt thanx for showing your code too...
Dipa AhujaPosted Mar 12, 2010, 8:29 AM
in some record its showing delete button where i wont bt in some its not..
i thing i have note is its not giving any effect on 1st record of gridview..
Sam HobbsPosted Mar 11, 2010, 11:34 PM
Dipa AhujaPosted Mar 11, 2010, 12:50 PM
aspx:
runat="server" Text="mydelete" />
.cs
pid = Convert.ToInt32(Request.QueryString["profileId"].ToString());
public bool isOwner(int scrapId)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
Label lbl = (Label)GridView1.Rows[i].FindControl("lblfromId");
if (lbl.Text == pid.ToString())
{
return true;
}
else
{
return false;
}
}
}
but its giving error:
'scrapboook.isOwner(int)': not all code paths return a value
Lalit MPosted Mar 10, 2010, 12:29 AM
show here sample code
checkbox
delete button
CS Code sample
bool OneChecked = false;
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Button Button1 = (Button)GridView1.HeaderRow.FindControl("Button1");
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox CheckBox1 = (CheckBox)row.FindControl("CheckBox1");
if (CheckBox1.Checked == true)
{
OneChecked = true;
}
}
if (OneChecked == false)
{
Button1.Enabled = false;
}
else if (OneChecked == true)
{
Button1.Enabled = true;
}
}
Amit ChoudharyPosted Mar 10, 2010, 12:24 AM
Create you button inside the grid view like this:
now create a method in code behind
{I hope your problem get solved.
Please Don't forget to mark as answer.