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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 11, 2010, 6:59 PM EST
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.
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 9, 2010, 7:24 PM EST
Create you button inside the grid view like this:
now create a method in code behind
// Check if the owner of Scrap using Scrapid is equal to the Logged in User if( ) return true; else return false;I hope your problem get solved.
Please Don't forget to mark as answer.
Lalit MRank #1,186 · 1.5K reputationPosted Mar 9, 2010, 7:29 PM EST
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;
}
}
Dipa AhujaRank #1,168 · 1.5K reputationPosted Mar 11, 2010, 7:50 AM EST
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
Sam HobbsRank #107 · 20.5K reputationPosted Mar 11, 2010, 6:34 PM EST
Dipa AhujaRank #1,168 · 1.5K reputationPosted Mar 12, 2010, 3:29 AM EST
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..
Dipa AhujaRank #1,168 · 1.5K reputationPosted Mar 12, 2010, 5:59 AM EST
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...
Sandeep Sharma50 reputationPosted Aug 5, 2014, 5:41 AM EDT
this is working for me try something like this.